標籤:
運用uiview的幾個animation方面可以使動畫變的更加簡單
1. 如果是view properties 的變化,使用以下方法
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
可以用作animation的properties有:frame,bounds,center,alpha, transform(setTransform),bkgcolor
如果options中有repeat 選項,那麼該如何停止動畫呢?
可用[self.layer removeAllAnimations];停止動畫
更多控制,設定 CAMediaTiming中properties(可參考http://www.cnblogs.com/gaoxiao228/archive/2013/01/28/2880285.html)
2. 如果是view 的hierachy 變化,使用以下方法:
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion ;+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion; // toView added to fromView.superview, fromView removed from its superview
iOS開發總結(A0)- UIView Animation