iOS动画-UIKitAnimation

一、      UIKitAnimation——进行一些比较简单的动画,比渐变、旋转,平移,翻转

 

1.UIViewGeometry类:

 

相关属性如下:

 

transform//CGAffineTransform类型的仿射变换,视图上的转换矩阵,相对于视图边界的中心。

//CGAffineTransform包括平移函数,缩放函数,旋转函数。分别是:

*CGAffineTransformMakeTranslation(CGFloattx,

  CGFloat ty)函数中的两个参数指定X和Y方向上以点为单位的平移量。

*  CGAffineTransformMakeScale(CGFloatsx, CGFloat sy)函数中的两个参数分别指缩放x轴和缩放y轴。

*  CGAffineTransformMakeRotation(CGFloatangle)函数中的参数为旋转角度

 

contentMode//决定边界变化和缩放操作作用到视图上产生的效果。

autoresizingMask//设置视图的尺寸变化

autoresizesSubviews//为YES时其子视图会根据autoresizingMask属性的值自动进行尺寸调整;否则应用程序必须通过重载layoutSubviews方法来提供自己的实现。

 

//以下方法用于在不同的视图本地坐标系之间进行坐标转换

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView*)view;

- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView*)view;

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect fromView:(UIView*)view;

 

2. UIViewHierarchy

相关属性如下:

 

//以下方法用于对父视图的子视图进行重新排序

- (void)insertSubview:(UIView *)viewatIndex:(NSInteger)index;

- (void)insertSubview:(UIView *)view belowSubview:(UIView*)siblingSubview;

- (void)insertSubview:(UIView *)view aboveSubview:(UIView*)siblingSubview;

 

//以下方法用于在父视图的子视图列表中间插入视图

- (void)bringSubviewToFront:(UIView *)view;

- (void)sendSubviewToBack:(UIView *)view;

- (void)exchangeSubviewAtIndex:(NSInteger)index1

withSubviewAtIndex:(NSInteger)index2;

 

//以下方法用于当您为某个视图添加子视图时,UIKit会向相应的父子视图发送几个消息,通知它们当前发生的状态变化。您可以在自己的定制视图中对以下方法进行重载,以便在事件发生的前后进行必要的处理,并根据发生的变化更新视图状态信息

- (void)willMoveToSuperview:(UIView *)newSuperview;

- (void)didMoveToSuperview;

- (void)willMoveToWindow:(UIWindow *)newWindow;

- (void)didMoveToWindow;

- (void)didAddSubview:(UIView *)subview;

- (void)willRemoveSubview:(UIView *)subview;

 

//以下方法用来判定一个视图是否在其父视图的视图层中

- (BOOL)isDescendantOfView:(UIView *)view;

 

//以下方法用于对视图进行布局

- (void)setNeedsLayout;

- (void)layoutIfNeeded;

3. UIViewAnimation

 

相关属性如下:

 

+ (void)beginAnimations:(NSString *)animationIDcontext:(void *)context
//*UIKit实现动画的起点,开始一个动画块,第一个参数是一个可选的动画的名字,第二个参数是一个可选的上下文,在之后传递给动画的委托方法时你可以获得它。

*参数
animationID-应用程序提供的字符串,用于标识一个动画块中的动画

*context-应用程序提供的对象,用于向委托对象传递额外的信息*/

 

+ (void)setAnimationDuration:(NSTimeInterval)duration;//设置动画持续的秒数

+ (void)setAnimationDelegate:(id)delegate;//设置一个对象来接收动画开始之前、动画期间或动画结束之后发生的各种事件的委托对象。

+ (void)setAnimationDidStopSelector:(SEL)selector;//设置动画完成时委托对象中应该被调用的方法。消息处理方法的形式为:-animationWillStart:(NSString *)animationIDcontext:(void *)context

-animationDidStop:(NSString *)animationIDfinished:(NSNumber *)finished context:(void *)context

 

+ (void)setAnimationWillStartSelector:(SEL)selector; //设置动画即将开始时委托对象中被调用的选择器。

+ (void)setAnimationDelay:(NSTimeInterval)delay; ;//设置实际发生动画和commitAnimations方法返回的时间点之间的间隔。

+setAnimationRepeatCount://设置动画的持续次数

+ (void)setAnimationStartDate:(NSDate *)startDate;//设置动画在commitAnimations方法返回之后的发生日期。缺省行为是使动画立即在线程中执行 

+setAnimationCurve://设置动画过程的相对速度

+setAnimationRepeatAutoreverses://指定动画在到达目标值时是否自动返回播放

+ (void)commitAnimations; // 运行动画

 

 

举例:

- (void)viewDidAppear:(BOOL)paramAnimated{

[super viewDidAppear:paramAnimated]; self.xcodeImageView.center =self.view.center;


[UIView beginAnimations:@"clockwiseAnimation" context:NULL];//开始动画

[UIView setAnimationDuration:5.0f];//动画时间为5.0s

[UIView setAnimationDelegate:self]; //设置代理

[UIView setAnimationDidStopSelector:

@selector(clockwiseRotationStopped:finished:context:)];//委托选择器

self.xcodeImageView.transform =

CGAffineTransformMakeRotation((90.0f * M_PI) / 180.0f);/ 图形旋转90  

 [UIView commitAnimations];//执行动画

**********************************

**********************************

4.常使用block方法举例:UIView(UIViewAnimationWithBlocks)

1. [UIViewanimateWithDuration:1.0 animations:^{

        fadeMeView.alpha = 0.0f;//透明度变为0

     }];//实现渐变效果

 

[UIView animateWithDuration:0.5 animations:^{

moveMeView.center = CGPointMake(moveMeView.center.x,moveMeView.center.y-200);/y轴移动200

}];

}//实现平移效果

2. [UIView transitionWithView:noteViewduration:0.6

 options:UIViewAnimationOptionTransitionCurlUp

animations:^{

NSString *currentText =noteView.text;

noteView.text =nextText;

self.nextText = currentText;//变换noteView上显示的内容

}completion:^(BOOL finished){

 

}];//实现翻书、翻页效果

 

3. //双面图((UIViewfrontView、(UIImageViewbackView)、(BOOLdisplayingFrontView

[UIView transitionFromView:(displayingFrontView)?frontView : backView

toView:(displayingFrontView) ?backView : frontView

 duration:0.75 

 options:(displayingFrontView?UIViewAnimationOptionTransitionFlipFromRight:UIViewAnimationOptionTransitionFlipFromLeft)

completion:^(BOOL finished) {

if (finished) {

displayingFrontView =!displayingFrontView;

}

}];

}//实现同一物体的翻转

  

4.+(void)animateWithDuration:(NSTimeInterval)durationdelay:(NSTimeInterval)delay options:(UIViewAnimationOptions)optionsanimations:(void (^)(void))animations completion:(void (^)(BOOLfinished))completion

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值