简体   繁体   English

iPhone:使用Core Animation过渡视图

[英]iPhone: transitioning views with Core Animation

On the Mac, the best way for a simple cross-fade transition of views (without any custom keyframe timing) is to do something such as the following excerpt: 在Mac上,简单的跨淡入淡出视图过渡(没有任何自定义关键帧定时)的最佳方法是执行以下摘录:

[[self animator] replaceSubview:aView with:bView];

Unfortunately the animator property isn't available on the iPhone. 不幸的是,动画师属性在iPhone上不可用。 What's the best bet of doing this on the iPhone? 在iPhone上执行此操作的最佳选择是什么? Is it setting alpha channels on each view? 是否在每个视图上设置Alpha通道? Sample code would be excellent. 示例代码将是极好的。

Thanks. 谢谢。

The basic way to animate views on the iphone is to use the UIView beginAnimations and commitAnimations calls. 在iPhone上制作视图动画的基本方法是使用UIView beginAnimations和commitAnimations调用。 They allow you to modify the animatable properties of a view and have those changes animated. 它们使您可以修改视图的动画属性,并使这些更改具有动画效果。

For instance I have a custom view that is hidden and shown using this approach: 例如,我有一个使用此方法隐藏和显示的自定义视图:

- (void) showAView:(CustomAView *)aView
{
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.5];    
  aView.frame = CGRectMake(0.0f, 110.0f , aView.frame.size.width, aView.frame.size.height);
  [UIView commitAnimations];  
}

- (void) hideAView:(CustomAView *)aView
{
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.5];  
  aView.frame = CGRectMake(0.0f, self.view.frame.size.height, aView.frame.size.width, aView.frame.size.height);    
  [UIView commitAnimations];
}

By wrapping the frame property change in the UIView beginAnimations/commitAnimations the change has a standard animation applied to it. 通过将框架属性更改包装在UIView beginAnimations / commitAnimations中,更改将应用​​标准动画。

You can add additional properties to the animation by using UIView animation class methods eg. 您可以使用UIView动画类方法将其他属性添加到动画中。

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

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

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