IOS图像5之UIView动画、自定义转场动画、delegate
2014-12-20 10:33
519 查看
UIView淡入淡出动画、3D旋转动画
淡入淡出动画
UIView *view01 = [[UIView
alloc]initWithFrame:CGRectMake(20,
20, 100,
50)];
view01.backgroundColor = [UIColor
redColor];
[self.view
addSubview:view01];
view01.alpha =
1.0;
[UIView beginAnimations:nil
context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:3.0];
[UIView setAnimationRepeatCount:3];
[UIView setAnimationDelegate:self];
view01.alpha =
0.0;
[UIView commitAnimations];
3D旋转Block动画:
UIView *view01 = [[UIView
alloc]initWithFrame:CGRectMake(20,
20, 100,
50)];
[UIView animateWithDuration:2
animations:^{
view01.backgroundColor = [UIColor
cyanColor];
view01.alpha =
1.0;
[self.view
addSubview:view01];
[UIView
setAnimationDuration:2.0];
[UIView
setAnimationRepeatCount:1.0];
[UIView
setAnimationCurve:UIViewAnimationCurveEaseInOut];
view01.transform =
CGAffineTransformMakeRotation(3.14);
} completion:^(BOOL finish){
if (finish) {
NSLog(@"animationstop");
}
这里设置动画结束之后还有一些代理方法,例如stop动画结束的完成回调方法,start动画开始回调方法等等。
自定义转场动画:
从IOS7之后可以定义自定义转场动画:
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
UIViewController * viewfrom = [transitionContext
viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * viewto = [transitionContext
viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *mtransitionContext = [transitionContext
containerView];
[mtransitionContext
addSubview:viewfrom.view];
[mtransitionContext
addSubview:viewto.view];
viewto.view.frame =
CGRectMake(100,
0, 320,
568);
[UIView
animateWithDuration:5.0
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^(){
viewto.view.frame =
CGRectMake(0,
0, 320,
568);
}
completion:^(BOOL finished){
[transitionContext
completeTransition:YES];
}];
}
剩下的我们只需要实现navigation的代理协议就可以了:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController
*)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController
*)toVC{
id anim = nil;
anim =
mslid;
return anim;
}
淡入淡出动画
UIView *view01 = [[UIView
alloc]initWithFrame:CGRectMake(20,
20, 100,
50)];
view01.backgroundColor = [UIColor
redColor];
[self.view
addSubview:view01];
view01.alpha =
1.0;
[UIView beginAnimations:nil
context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:3.0];
[UIView setAnimationRepeatCount:3];
[UIView setAnimationDelegate:self];
view01.alpha =
0.0;
[UIView commitAnimations];
3D旋转Block动画:
UIView *view01 = [[UIView
alloc]initWithFrame:CGRectMake(20,
20, 100,
50)];
[UIView animateWithDuration:2
animations:^{
view01.backgroundColor = [UIColor
cyanColor];
view01.alpha =
1.0;
[self.view
addSubview:view01];
[UIView
setAnimationDuration:2.0];
[UIView
setAnimationRepeatCount:1.0];
[UIView
setAnimationCurve:UIViewAnimationCurveEaseInOut];
view01.transform =
CGAffineTransformMakeRotation(3.14);
} completion:^(BOOL finish){
if (finish) {
NSLog(@"animationstop");
}
这里设置动画结束之后还有一些代理方法,例如stop动画结束的完成回调方法,start动画开始回调方法等等。
自定义转场动画:
从IOS7之后可以定义自定义转场动画:
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
UIViewController * viewfrom = [transitionContext
viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * viewto = [transitionContext
viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *mtransitionContext = [transitionContext
containerView];
[mtransitionContext
addSubview:viewfrom.view];
[mtransitionContext
addSubview:viewto.view];
viewto.view.frame =
CGRectMake(100,
0, 320,
568);
[UIView
animateWithDuration:5.0
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^(){
viewto.view.frame =
CGRectMake(0,
0, 320,
568);
}
completion:^(BOOL finished){
[transitionContext
completeTransition:YES];
}];
}
剩下的我们只需要实现navigation的代理协议就可以了:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController
*)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController
*)toVC{
id anim = nil;
anim =
mslid;
return anim;
}
相关文章推荐
- IOS图像8之IOS7.0之后UIViewController自定义转场动画
- [iOS Swift] 自定义转场动画 UIViewControllerAnimatedTransitioning 报错
- iOS 7:自定义导航转场动画以及更多
- iOS 自定义push转场动画
- iOS自定义转场动画(4)——自定义模态跳转之dismiss与手势驱动
- iOS自定义转场动画实战讲解
- iOS 8自定义动画转场上手指南
- iOS自定义转场动画
- iOS:UIView的block函数实现转场动画---单视图
- IOS 自定义转场动画
- iOS 7:自定义导航转场动画以及更多
- iOS自定义转场动画
- iOS 8自定义动画转场上手指南
- iOS自定义转场动画
- 详解iOS开发中的转场动画和组动画以及UIView封装动画
- iOS 7:自定义导航转场动画以及更多
- 【Swift】IOS开发中自定义转场动画
- iOS动画开发之三——UIView的转场切换
- 源码推荐(8.17):闪屏效果,简易动画引擎,iOS UIView自定义四个边角的圆角
- IOS实战之自定义转场动画详解