iphone - 将 UIButton 向下移动 10px 并打开新的 ViewController

标签 iphone objective-c ios uibutton

我是 iOS 开发的新手,这是我关于 SO 的第一个问题。

我想制作“动画”。

当我点击 UIButton 时,我想慢慢地(大约 0.5 秒)将它向下移动 10px,当我抬起手指时,我想打开新的 viewController。

我制作了东西,但我不知道如何制作“动画”。

    UIImage *normalImage = [UIImage imageNamed:@"FirstImage"];        
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    firstButton.frame = CGRectMake(31, 194, normalImage.size.width, normalImage.size.height);
    [firstButton setImage:normalImage forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(showSecondViewController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:firstButton];


- (void)showSecondViewController; {
    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    secondViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:secondViewController animated:YES];
    [progressViewController release]; 
}

最佳答案

[UIView animateWithDuration:(NSTimeInterval)duration animations:^(void) {
    //put your animation result here
    //then it will do animation for you
} completion:^(BOOL finished){
    //do what you need to do after animation complete
}];

例如:

UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//add firstButton to some view~
//....

firstButton.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.5 animations:^(void) {
    firstButton.transform = CGAffineTransformMakeTranslation(0,10);
} completion:^(BOOL finished){
    show your view controller~
}];

关于iphone - 将 UIButton 向下移动 10px 并打开新的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8588002/

相关文章:

iphone - 使用未声明的标识符 - 核心数据

iphone - 找不到“RevMobAds/RevMobAds.h”文件

ios - 在 rowindexpath 的 tableView 中删除项目会删除它下面的项目吗?

ios - 代码 : Reload UITableViewCell

ios - 我还可以为 iPhone 4s 申请吗?

css - HTML 电子邮件中 ​​div 的 100% 宽度样式在 iPhone 上不起作用

iphone - iPad 快速显示图像时出现重影

ios - Xcode 6 中不同设备的不同 Storyboard

objective-c - 当模拟器从 XCode 关闭时,是否有运行的方法?

android - Android 正在读取 SQLite 中的 iOS 日期(NSDate)