iOS进阶高级JG专题iOS-OC中级

iOS开发高级进阶(8-10)-动画

2016-03-12  本文已影响450人  逸飞u

(还是没搞懂。。。继续看参考中)
交互设计的一部分:布局、变换

UIKit

UIView提供的动画支持

UIView可动画的属性

动画效果一览

  typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
    UIViewAnimationOptionLayoutSubviews            = 1 <<  0,
    UIViewAnimationOptionAllowUserInteraction      = 1 <<  1, // turn on user interaction while animating
    UIViewAnimationOptionBeginFromCurrentState     = 1 <<  2, // start all views from current value, not initial value
    UIViewAnimationOptionRepeat                    = 1 <<  3, // repeat animation indefinitely
    UIViewAnimationOptionAutoreverse               = 1 <<  4, // if repeat, run animation back and forth
    UIViewAnimationOptionOverrideInheritedDuration = 1 <<  5, // ignore nested duration
    UIViewAnimationOptionOverrideInheritedCurve    = 1 <<  6, // ignore nested curve
    UIViewAnimationOptionAllowAnimatedContent      = 1 <<  7, // animate contents (applies to transitions only)
    UIViewAnimationOptionShowHideTransitionViews   = 1 <<  8, // flip to/from hidden state instead of adding/removing
    UIViewAnimationOptionOverrideInheritedOptions  = 1 <<  9, // do not inherit any options or animation type

    UIViewAnimationOptionCurveEaseInOut            = 0 << 16, // default
    UIViewAnimationOptionCurveEaseIn               = 1 << 16,
    UIViewAnimationOptionCurveEaseOut              = 2 << 16,
    UIViewAnimationOptionCurveLinear               = 3 << 16,

    UIViewAnimationOptionTransitionNone            = 0 << 20, // default
    UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
    UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
    UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
    UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
    UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
    UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
    UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
} ;

UIView的Keyframe动画(可控制中间状态)

+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations; // start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation

Spring Animation

参考:https://www.renfei.org/blog/ios-8-spring-animation.html

Autolayout环境下的动画

  1. 通过修改constraint实现
    2. 生效[self.view setNeedsUpdateConstraints];
  2. 在更改动画块
    [self.view layoutIfNeeded];

View Transition用动画切换新界面

transitionWithView(子View)

[UIView transitionWithView:(nonnull UIView *)
                       duration:(NSTimeInterval)
                       options:(UIViewAnimationOptions)
                       animations:^(void)animations
                       completion:^(BOOL finished)completion];

//UIViewAnimationOptions
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
    UIViewAnimationOptionLayoutSubviews            = 1 <<  0,
    UIViewAnimationOptionAllowUserInteraction      = 1 <<  1, // turn on user interaction while animating
    UIViewAnimationOptionBeginFromCurrentState     = 1 <<  2, // start all views from current value, not initial value
    UIViewAnimationOptionRepeat                    = 1 <<  3, // repeat animation indefinitely
    UIViewAnimationOptionAutoreverse               = 1 <<  4, // if repeat, run animation back and forth
    UIViewAnimationOptionOverrideInheritedDuration = 1 <<  5, // ignore nested duration
    UIViewAnimationOptionOverrideInheritedCurve    = 1 <<  6, // ignore nested curve
    UIViewAnimationOptionAllowAnimatedContent      = 1 <<  7, // animate contents (applies to transitions only)
    UIViewAnimationOptionShowHideTransitionViews   = 1 <<  8, // flip to/from hidden state instead of adding/removing
    UIViewAnimationOptionOverrideInheritedOptions  = 1 <<  9, // do not inherit any options or animation type

    UIViewAnimationOptionCurveEaseInOut            = 0 << 16, // default
    UIViewAnimationOptionCurveEaseIn               = 1 << 16,
    UIViewAnimationOptionCurveEaseOut              = 2 << 16,
    UIViewAnimationOptionCurveLinear               = 3 << 16,

    UIViewAnimationOptionTransitionNone            = 0 << 20, // default
    UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
    UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
    UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
    UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
    UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
    UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
    UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
} ;
//animations:block

视图替换(场景变换较大)

[UIView transitionFromView:(nonnull UIView *)
                     toView:(nonnull UIView *)
                     duration:(NSTimeInterval) 
                     options:(UIViewAnimationOptions) 
                     completion:^(BOOL finished)completion];

Core Animation(操纵Layer形成动画效果)

CATransaction

进一步学习:

Implicit Animation(隐式动画)

Layer可动画的属性

Layer可动画的属性.png

Todolist:一个一个试试

隐式动画的查找

???什么用?

CAAction

作用:禁止隐式动画(让-actionForKey找不到CAAction)
实现:

//1.  return nil in delegate(CAAction) -actionForLayer:forKey; 
-(id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event{
    return  nil;
}
//2.
  [CATransaction setDisableActions:YES];

显式动画CAAnimation

接口:

1、CAAction
2、CAMediaTiming

子类:

混合View及Layer动画

<待补充>

上一篇下一篇

猜你喜欢

热点阅读