`

iOS动画

阅读更多
iOS页面切换动画实现方式。
1.使用UIView animateWithDuration:animations:completion方法
[UIView animateWithDuration:0.2f animations:^{
        detail.view.frame = CGRectMake(0, 0, detail.view.frame.size.width, detail.view.frame.size.height);
    } completion:^(BOOL finished) {
        UITableViewCell *cell = [articleTable cellForRowAtIndexPath:idx];
        cell.backgroundColor = [UIColor clearColor];
    }];

2.使用UIView beginAnimations:context和UIView commitAnimations方法
[UIView beginAnimations:nil context: nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];//指定动画方式为卷帘向下,类似的动画切换方式有CurlUp、FlipFromLeft、FlipFromRight,对应Apple Developer Documents中的枚举结构如下
//UIViewAnimationTransition
//Specifies a transition to apply to a view in an animation block.
//typedef enum {
//   UIViewAnimationTransitionNone,
//   UIViewAnimationTransitionFlipFromLeft,
//   UIViewAnimationTransitionFlipFromRight,
//   UIViewAnimationTransitionCurlUp,
//   UIViewAnimationTransitionCurlDown,
//} UIViewAnimationTransition;

//要动画改变的属性
self.view.alpha = 0.0;//动画改变透明度
self.view.frame = CGRectMake(10, 10, 50, 50);//动画将视图改变到指定位置指定大小
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

[UIView commitAnimations];//提交动画


3.使用QuartzCore框架中的CATransition
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = kDuration;
animation.timingFunction = UIViewAnimationCurveEaseInOut;//动画的开始与结束的快慢
animation.type = kCATransitionFade;//指定动画方式为Fade渐隐消去、类似还有kCATransitionPush、kCATransitionReveal、kCATransitionMoveIn、@"cube"、@"suckEffect"、@"oglFlip"、@"rippleEffect"、@"pageCurl"、@"pageUnCurl"、@"cameraIrisHollowOpen"、@"cameraIrisHollowClose"等,
//pageCurl 向上翻一页
//pageUnCurl 向下翻一页
//rippleEffect 滴水效果
//suckEffect 收缩效果,如一块布被抽走
//cube 立方体效果
//oglFlip 上下翻转效果
//cameraIrisHollowOpen 相机打开效果
//cameraIrisHollowClose 相机关闭效果
Apple Developer Documents中介绍如下
//Common Transition Types
//These constants specify the transition types that can be used with the type property.
//NSString * const kCATransitionFade;
//NSString * const kCATransitionMoveIn;
//NSString * const kCATransitionPush;
//NSString * const kCATransitionReveal;
animation.subtype = kCATransitionFromLeft;//指定动画进行方向从左边开始,类似还有kCATransitionFromBottom、kCATransitionFromRight、kCATransitionFromTop,Apple Developer Documents中介绍如下
//Common Transition Subtypes
//These constants specify the direction of motion-based transitions. They are used //with the subtype property.
//NSString * const kCATransitionFromRight;
//NSString * const kCATransitionFromLeft;
//NSString * const kCATransitionFromTop;
//NSString * const kCATransitionFromBottom;

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[[self.view layer] addAnimation:animation forKey:@"animation"];
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics