我是 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/