我正在使用这个从另一个 View Controller 调用一个方法:
InitialViewController *secondController = [[InitialViewController alloc] init];
[secondController forecast];
这是 InitialViewController 中的方法:
-(void)forecast{
[UIView beginAnimations:@"Forecast" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0f];
self.customPager.frame = CGRectMake(0,5, 320, 510);
self.view1.frame = CGRectMake(-320,5, 320, 510);
radarView.frame = CGRectMake(0,560, 320, 510);
[UIView commitAnimations];
NSLog(@"Method Passed");
}
在我的控制台中,我收到 NSLog“方法已通过”,但根本没有出现 UIView 动画。有什么想法吗?
最佳答案
在我看来,您没有以任何方式显示与 secondController
关联的 View 。即,做完之后:
InitialViewController *secondController = [[InitialViewController alloc] init];
我希望你做这样的事情:
[self.view addSubview:secondController.view];
这会在您调用 forecast
之前触发 loadView/viewDidLoad
。此外,我会给 UI 一个机会,让它在动画之前显示您的 View ;因此,我会这样调用 forecast
:
[self performSelector:@selector(forecast) withObject:nil afterDelay:0.0];
或来自viewDidAppear
。
编辑:
根据您的评论,
您的 InitialViewController
已经显示在屏幕上。在这种情况下,您应该做的是获取对它的引用并向它发送 forecast
消息。
你现在正在做的是实例化一个新的 InitialViewController
(然后向它发送 forecast
消息),它与已经显示的那个没有任何关系。
关于iphone - 从不同的 View Controller 调用时,UIView 动画不会触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14675860/