简体   繁体   English

CATransition和特定执行时间

[英]CATransition and Specific Execution Time

Look at this sample code (in AppDelegate): 查看以下示例代码(在AppDelegate中):

- (void)showOtherView {
if (self.viewController.view == view1) {
    self.viewController.view = view2;
} else {
    self.viewController.view = view1;
}
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:@"myKey"];

} }

This method simply switches view1 to view2 . 此方法只是将view1切换到view2 The thing I don't understand is, that CATransition is declared and added to window.layer after assigning view2 to self.viewController.view . 我不明白的事情是,那CATransition声明,并添加到self.viewController.view分配视图2window.layer。 Why does the animation works? 为什么动画有效?

I did set breakpoints and figured out that switching animates after showOtherView method is finished. 我确实设置了断点,并弄清楚在showOtherView方法完成后切换动画。 Why? 为什么? Just why view2 doesn't instantly appear on the screen!? 为什么view2不会立即出现在屏幕上!? (at least for the first time I call this method) (至少我第一次调用此方法)

Drawing to the screen is an expensive operation, and Cocoa only does it once per spin of the run loop , at the end. 绘制到屏幕上是一项昂贵的操作,并且可可在运行循环的最后每转仅进行一次 The effects of setting the controller's view -- it getting put on the screen -- don't actually happen until after this method has returned and control passes to the run loop. 设置控制器视图的效果(将其放置在屏幕上)实际上直到该方法返回并且控制权传递到运行循环后才发生。 So whatever configurations you make to the new view will always be shown. 因此,将始终显示您对新视图所做的任何配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM