gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:42:26 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com