我从其他 SO 问题中获取了一些代码,但我一定是在做一些奇怪的事情。该应用程序从第一个 View 跳转到第三个 View 。我想要实现的是:
ViewController 1 Image 1 - 加载图像。快速交叉溶解到 ViewController 1 图像 2。
ViewController 1 Image 2 - 翻转到 ViewController 2。
发生了交叉溶解,但将我带到了 VC2。我一天中的大部分时间都在为此苦恼。该是我去浴缸里寻求帮助的时候了。
这是我一直在做的:
- (void)viewDidLoad
{
NSLog(@"%s", __FUNCTION__);
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
sleep (2);
[self transition1]; //showing image 1
}
- (void) transition1 {
NSLog(@"%s", __FUNCTION__);
/*
[UIView transitionFromView:firstView
toView:secondView
duration:3.0
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished) {
[firstView removeFromSuperview];
}];
*/
//this transition doesn't happen
UIImage * secondImage = [UIImage imageNamed:@"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
} completion:NULL];
sleep (2);
[self transition2];
}
- (void) transition2 {
NSLog(@"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad" bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns animated:YES completion:nil];
}
感谢您的帮助。
更新
我已经按照 Moxy 的建议更新了我的代码,如下所示:
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
[self performSelector:@selector(transition1)
withObject:nil
afterDelay:2.0f];
}
-(void)transition1
{
NSLog(@"%s", __FUNCTION__);
UIImage * secondImage = [UIImage imageNamed:@"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
}
completion:^(BOOL finished){
[self performSelector:@selector(transition2)
withObject:nil
afterDelay:2.0f];
}];
}
-(void)transition2
{
NSLog(@"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad"
bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns
animated:YES
completion:nil];
}
最佳答案
您需要做的就是在第一个动画的完成 block 中开始第二个动画。 Sleep() 是您可能不应该使用的东西。
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"%s", __FUNCTION__);
[self performSelector:@selector(transition1)
withObject:nil
afterDelay:2.0f]
}
-(void)transition1
{
NSLog(@"%s", __FUNCTION__);
UIImage * secondImage = [UIImage imageNamed:@"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
}
completion:^(BOOL finished){
[self performSelector:@selector(transition2)
withObject:nil
afterDelay:2.0f]
}];
}
-(void)transition2
{
NSLog(@"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad"
bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns
animated:YES
completion:nil];
}
关于iOS - 如何按顺序执行两个转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15180613/