我尝试用我的 View 中的图像制作动画,但它不起作用:我的图像位于没有动画的最终位置。
UIImage *myImg = [UIImage imageNamed : @"Img72.png"];
UIImageView *myImgView =[ [UIImageView alloc] initWithImage: myImg ];
myImgView.frame= CGRectMake(250,50,72,72);
[self.view addSubview:myImgView];
[UIView animateWithDuration:0.5
delay: 0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
[UIView setAnimationRepeatCount:100.0];
[UIView setAnimationRepeatAutoreverses:YES];
myImgView.frame= CGRectMake(50,250,72,72);
}
completion:NULL];
[myImgView release];
相同的动画代码在另一个 View 中完美运行。我终于发现它来 self 用这段代码显示 View 的方式:
FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //KO
[self presentModalViewController:controller animated:YES];
问题是 modalTransitionStyle
。当我评论该行(使用//KO)时,它终于起作用了。我测试了其他过渡样式和所有其他作品(UIModalTransitionStyleCoverVertical
、UIModalTransitionStyleCrossDissolve
、UIModalTransitionStylePartialCurl
)
我制作了一个viewDidLoadProject
(Utility App),并在viewDidLoad
方法的两个 View 中添加了动画代码。
问题出在哪里?这是苹果的错误吗?我怎样才能让翻转过渡和我的动画在第二个 View 中工作?
这是我的示例项目:http://dl.dropbox.com/u/9204589/testFlipAnimation.zip
最佳答案
当所有系统工作完成后开始使用界面似乎更自然,我相信 didAppear
必须用于该目的(是的,它有效 :))
FlipsideViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewDidAppear:(BOOL)animated
{
UIImage *myImg = [UIImage imageNamed : @"Img72.png"];
UIImageView *myImgView =[ [UIImageView alloc] initWithImage: myImg ];
myImgView.frame= CGRectMake(250,50,72,72);
[self.view addSubview:myImgView];
[UIView animateWithDuration:0.5
delay: 0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
[UIView setAnimationRepeatCount:100.0];
[UIView setAnimationRepeatAutoreverses:YES];
myImgView.frame= CGRectMake(50,250,72,72);
}
completion:NULL];
[myImgView release];
[super viewDidAppear:animated];
}
关于objective-c - 使用 UIModalTransitionStyleFlipHorizontal 呈现 View 时动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9777093/