iOS页面切换动画效果
来源:互联网 发布:淘宝宝贝描述规则 编辑:程序博客网 时间:2024/04/30 05:58
//// LAXAnimation.h// LAX_OCAnimation//// Created by 冰凉的枷锁 on 2016/11/18.// Copyright © 2016年 liuaoxiang. All rights reserved.//#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>#import <QuartzCore/QuartzCore.h>@interface LAXAnimation : NSObject@property (nonatomic, assign) NSTimer *timer;+ (CATransition *)defaultAnimationWithDuration:(NSTimeInterval)duration target:(UIView *)view;+ (CATransition *)animationWithDuration:(NSTimeInterval)duration target:(UIView *)view delegate:(id)delegate type:(NSInteger)type subtype:(NSInteger)subtype;+ (void)addShakeGestureRecognizer:(UIView *)view;+ (void)stopShakeWithTouchView:(UIView *)contentView shakeView:(UIView *)shakeView touches:(NSSet<UITouch *> *)touches event:(UIEvent *)event;@end
//// LAXAnimation.m// LAX_OCAnimation//// Created by 冰凉的枷锁 on 2016/11/18.// Copyright © 2016年 liuaoxiang. All rights reserved.//#import "LAXAnimation.h"@implementation LAXAnimation+ (CATransition *)defaultAnimationWithDuration:(NSTimeInterval)duration target:(UIView *)view { //默认动画 CATransition *defaultAnimation = [CATransition animation]; defaultAnimation.timingFunction = UIViewAnimationCurveEaseInOut; defaultAnimation.duration = duration; defaultAnimation.type = @"pageCurl"; defaultAnimation.subtype = kCATransitionFromBottom; //defaultAnimation.delegate = self; [view.layer addAnimation:defaultAnimation forKey:@"animation"]; return defaultAnimation;}+ (CATransition *)animationWithDuration:(NSTimeInterval)duration target:(UIView *)view delegate:(nullable id)delegate type:(NSInteger)type subtype:(NSInteger)subtype { //NSArray *titleArr = @[@"淡化", @"推挤", @"揭开", @"覆盖", @"波纹", @"吸收", @"翻转", @"立方体", @"翻页", @"反翻页", @"镜头开", @"镜头关"]; NSArray *typeArr = @[kCATransitionFade, kCATransitionPush, kCATransitionReveal, kCATransitionMoveIn, @"rippleEffect", @"suckEffect", @"oglFlip", @"cube", @"pageCurl", @"pageUnCurl", @"cameraIrisHollowOpen", @"cameraIrisHollowClose"]; NSArray *subtypeArr = @[kCATransitionFromLeft, kCATransitionFromBottom, kCATransitionFromRight, kCATransitionFromTop]; CATransition *defaultAnimation = [CATransition animation]; defaultAnimation.delegate = delegate; defaultAnimation.duration = duration; defaultAnimation.timingFunction = UIViewAnimationCurveEaseInOut; if (type >= 0 && type < 12) { defaultAnimation.type = typeArr[type]; } if (type >= 0 && type < 4) { defaultAnimation.subtype = subtypeArr[subtype]; } [view.layer addAnimation:defaultAnimation forKey:@"animation"]; return defaultAnimation;}+ (void)addShakeGestureRecognizer:(UIView *)view { //向view添加长按手势 UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; longPress.minimumPressDuration = 1; [view addGestureRecognizer:longPress]; view.userInteractionEnabled = YES;}+ (void)startShake:(UIView *)view { //创建动画对象,绕Z轴旋转 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //设置属性,周期时长 [animation setDuration:0.08]; //抖动角度 animation.fromValue = @(-M_1_PI/2); animation.toValue = @(M_1_PI/2); //重复次数,无限大 animation.repeatCount = HUGE_VAL; //恢复原样 animation.autoreverses = YES; //锚点设置为图片中心,绕中心抖动 view.layer.anchorPoint = CGPointMake(0.5, 0.5); [view.layer addAnimation:animation forKey:@"rotation"];}+ (void)gestureAction:(UILongPressGestureRecognizer *)sender { CABasicAnimation *animation = (CABasicAnimation *)[sender.view.layer animationForKey:@"rotation"]; if (animation == nil) { [self startShake:sender.view]; }else { sender.view.layer.speed = 1.0; }}+ (void)stopShakeWithTouchView:(UIView *)contentView shakeView:(UIView *)shakeView touches:(NSSet<UITouch *> *)touches event:(UIEvent *)event { //判断touch点是否在imageView内,在的话,仍然抖动,否则停止抖动 UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:contentView]; CGPoint p = [contentView convertPoint:point toView:shakeView]; //NSLog(@"%d,%d", p.x, p.y); if (![shakeView pointInside:p withEvent:event]) { shakeView.layer.speed = 0.0; }}@end
0 0
- iOS页面切换动画效果
- android 页面切换动画效果
- android 页面切换动画效果
- 页面切换动画效果1
- 页面切换动画效果2
- 页面切换动画效果3
- 页面切换动画效果4
- 页面切换动画效果5
- qml页面切换动画效果
- ios 视图切换动画效果
- ios 视图切换动画效果
- ios 视图切换动画效果
- ios 视图切换动画效果
- IOS页面切换过渡动画
- 页面切换动画效果(tabBar事件)
- Android 定制页面切换动画效果
- 安卓页面切换添加动画效果
- 使用CircularReveal动画效果切换页面
- 浏览器无法连接的解决方法 windows无法与设备和资源通信的解决方法
- 零基础学习PHP:学前简介(一)
- eclipse下maven打包"错误: 编码GBK的不可映射字符"
- 使用jquery触发a标签跳转
- WebConfig配置文件详解
- iOS页面切换动画效果
- leetcode 167. Two Sum II
- 380. Insert Delete GetRandom O(1)
- 填坑日记2017.3.6
- 关于JAVA数组的几点注意事项与一些低级错误
- 十大排序算法
- Linux学习笔记-脚本(鸟哥13章)
- Problem--266A--Codeforces--Stones on the Table
- max nesting level reach '100'