ios 手势操作举例

#import "ViewController.h"
@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *targetView;

@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    /*
     UIGestureRecognizer
     父类手势带给的东西
     初始化方法:
     - (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action NS_DESIGNATED_INITIALIZER;
     给手势添加事件和移动事件
     手势的状态

     */
    //添加单击手势
    UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTapAction:)];
    [self.view addGestureRecognizer:singleTap];
    //双击
    UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTapAction:)];
    doubleTap.numberOfTouchesRequired=2;
    [self.view addGestureRecognizer:doubleTap];
    //单击要想执行必须双击失效
    [singleTap requireGestureRecognizerToFail:doubleTap];
    //长按手势,
    UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
    [self.targetView addGestureRecognizer:longPress];
    //捏合手势
    UIPinchGestureRecognizer *pinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGestureAction:)];
    [self.targetView addGestureRecognizer:pinchGesture];
    //拖拽
    UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    [self.targetView addGestureRecognizer:panGesture];
    //旋转
    UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    [self.targetView addGestureRecognizer:rotation];
    //旋转要想执行必须缩放失效
    [pinchGesture requireGestureRecognizerToFail:rotation];
    //左横扫
    UISwipeGestureRecognizer *leftswipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeAction:)];
    [self.view addGestureRecognizer:leftswipeGesture];
    leftswipeGesture.direction=UISwipeGestureRecognizerDirectionLeft;
    //右横扫
    UISwipeGestureRecognizer *rightSwipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeAction:)];
    [self.view addGestureRecognizer:rightSwipeGesture];
    rightSwipeGesture.direction=UISwipeGestureRecognizerDirectionRight;
    //上横扫
    UISwipeGestureRecognizer *upswipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeAction:)];
    [self.view addGestureRecognizer:upswipeGesture];
    upswipeGesture.direction=UISwipeGestureRecognizerDirectionUp;
    //下横扫
    UISwipeGestureRecognizer *downSwipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeAction:)];
    [self.view addGestureRecognizer:downSwipeGesture];
    downSwipeGesture.direction=UISwipeGestureRecognizerDirectionDown;
}
//横扫
-(void)SwipeAction:(UISwipeGestureRecognizer *)sender{
    switch (sender.direction) {
        case UISwipeGestureRecognizerDirectionRight://从右向左滑
        {
            CATransition *animation=[CATransition animation];//创建CATransition 对象
            animation.delegate=self;  //动画代理
            animation.duration=1.0f;//动画持续时间
            animation.timingFunction=UIViewAnimationCurveEaseInOut;//速度控制函数,控制动画运行的节奏
            animation.type=kCATransitionMoveIn;//设置运动type
            animation.subtype=kCATransitionFromLeft;//视图向左滑
            [sender.view.layer addAnimation:animation forKey:@"move in"];
        }
            break;
        case UISwipeGestureRecognizerDirectionLeft://从左向右滑
        {
            CATransition *animation=[CATransition animation];
            animation.delegate=self;
            animation.duration=1.0f;
            animation.timingFunction=UIViewAnimationCurveEaseInOut;
            animation.type=kCATransitionMoveIn;
            animation.subtype=kCATransitionFromRight;
            [sender.view.layer addAnimation:animation forKey:@"move in"];
        }
            break;
        case UISwipeGestureRecognizerDirectionDown://向下滑
        {
            CATransition *animation=[CATransition animation];
            animation.delegate=self;
            animation.duration=1.0f;
            animation.timingFunction=UIViewAnimationCurveEaseInOut;
            animation.type=kCATransitionMoveIn;
            animation.subtype=kCATransitionFromBottom;
            [sender.view.layer addAnimation:animation forKey:@"move in"];
        }
            break;
        case UISwipeGestureRecognizerDirectionUp://向上滑
        {
            CATransition *animation=[CATransition animation];
            animation.delegate=self;
            animation.duration=1.0f;
            animation.timingFunction=UIViewAnimationCurveEaseInOut;
            animation.type=kCATransitionMoveIn;
            animation.subtype=kCATransitionFromTop;
            [sender.view.layer addAnimation:animation forKey:@"move in"];
        }
            break;
        default:
            break;
    }
}
//旋转
-(void)rotationAction:(UIRotationGestureRecognizer *)sender{
    sender.view.transform = CGAffineTransformRotate(sender.view.transform, sender.rotation);
    sender.rotation=10.0;//旋转速度
}
//拖拽
-(void)panAction:(UIPanGestureRecognizer *)sender{
   /* //当手势按在视图上面的点,转为父系坐标 拿到中心点
    CGPoint translatedPoint=[sender translationInView:self.view];
    CGFloat firstX;
    CGFloat firstY;
    if ([sender state]==UIGestureRecognizerStateBegan) {
         firstX=[sender.view center].x;
         firstY=[sender.view center].y;

    }
    translatedPoint=CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
    [sender.view setCenter:translatedPoint];*/
    //中心拖拽
   /* //当你的状态不等于结束状态,不等于失败状态
    if (sender.state != UIGestureRecognizerStateEnded && sender.state != UIGestureRecognizerStateFailed) {
        CGPoint location = [sender locationInView:sender.view.superview];
        sender.view.center = location;
    }*/

    //视图前置操作
    [sender.view.superview bringSubviewToFront:sender.view];
    //拖拽
    CGPoint center = sender.view.center;
    CGFloat cornerRadius = sender.view.frame.size.width / 2;
    CGPoint translation = [sender translationInView:self.view];
    //NSLog(@"%@", NSStringFromCGPoint(translation));
    sender.view.center = CGPointMake(center.x + translation.x, center.y + translation.y);
    [sender setTranslation:CGPointZero inView:self.view];
    //动画效果
    if (sender.state == UIGestureRecognizerStateEnded) {
        //计算速度向量的长度,当他小于200时,滑行会很短
        CGPoint velocity = [sender velocityInView:self.view];
        CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));
        CGFloat slideMult = magnitude / 200;
        //NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult); //e.g. 397.973175, slideMult: 1.989866

        //基于速度和速度因素计算一个终点
        float slideFactor = 0.1 * slideMult;
        CGPoint finalPoint = CGPointMake(center.x + (velocity.x * slideFactor),
                                         center.y + (velocity.y * slideFactor));
        //限制最小[cornerRadius]和最大边界值[self.view.bounds.size.width - cornerRadius],以免拖动出屏幕界限
        finalPoint.x = MIN(MAX(finalPoint.x, cornerRadius),self.view.bounds.size.width - cornerRadius);
        finalPoint.y = MIN(MAX(finalPoint.y, cornerRadius),self.view.bounds.size.height - cornerRadius);
        //使用 UIView 动画使 view 滑行到终点
        [UIView animateWithDuration:slideFactor*2 delay:0 options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             sender.view.center = finalPoint;
                         }
                         completion:nil];
    }
}
//缩放
-(void)pinchGestureAction:(UIPinchGestureRecognizer *)sender{
    NSLog(@"xxx");
    sender.view.transform=CGAffineTransformMakeScale(sender.scale, sender.scale);
}
//长按
-(void)longPressAction:(UILongPressGestureRecognizer *)sender{
    //长按出现通知框 ios 9
    if (sender.state==UIGestureRecognizerStateEnded) {
        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"标题" message:@"选择照片" preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *photoAction=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"调用照相机");
        }];
        [alertController addAction:photoAction];
        UIAlertAction *libraryAction=[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"调用本地相册");
        }];
        [alertController addAction:libraryAction];
        UIAlertAction *cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"取消");
        }];
        [alertController addAction:cancleAction];

        [self presentViewController:alertController animated:YES completion:nil];
    }
}
//单击
-(void)singleTapAction:(UITapGestureRecognizer *)sender{
    NSLog(@"你单了哈");
    //改变背景颜色
    if (sender.view.backgroundColor==[UIColor whiteColor]) {
        sender.view.backgroundColor=[UIColor cyanColor];
    }else{
        sender.view.backgroundColor=[UIColor whiteColor];
    }
}
//双击
-(void)doubleTapAction:(UITapGestureRecognizer *)sender{
    NSLog(@"双击");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。
VR(Virtual Reality)即虚拟现实,是一种可以创建和体验虚拟世界的计算机技术。它利用计算机生成一种模拟环境,是一种多源信息融合的、交互式的三维动态视景和实体行为的系统仿真,使用户沉浸到该环境中。VR技术通过模拟人的视觉、听觉、触觉等感觉器官功能,使人能够沉浸在计算机生成的虚拟境界中,并能够通过语言、手势等自然的方式与之进行实时交互,创建了一种适人化的多维信息空间。 VR技术具有以下主要特点: 沉浸感:用户感到作为主角存在于模拟环境中的真实程度。理想的模拟环境应该使用户难以分辨真假,使用户全身心地投入到计算机创建的三维虚拟环境中,该环境中的一切看上去是真的,听上去是真的,动起来是真的,甚至闻起来、尝起来等一切感觉都是真的,如同在现实世界中的感觉一样。 交互性:用户对模拟环境内物体的可操作程度和从环境得到反馈的自然程度(包括实时性)。例如,用户可以用手去直接抓取模拟环境中虚拟的物体,这时手有握着东西的感觉,并可以感觉物体的重量,视野中被抓的物体也能立刻随着手的移动而移动。 构想性:也称想象性,指用户沉浸在多维信息空间中,依靠自己的感知和认知能力获取知识,发挥主观能动性,寻求解答,形成新的概念。此概念不仅是指观念上或语言上的创意,而且可以是指对某些客观存在事物的创造性设想和安排。 VR技术可以应用于各个领域,如游戏、娱乐、教育、医疗、军事、房地产、工业仿真等。随着VR技术的不断发展,它正在改变人们的生活和工作方式,为人们带来全新的体验。
基于GPT-SoVITS的视频剪辑快捷配音工具 GPT, 通常指的是“Generative Pre-trained Transformer”(生成式预训练转换器),是一个在自然语言处理(NLP)领域非常流行的深度学习模型架构。GPT模型由OpenAI公司开发,并在多个NLP任务上取得了显著的性能提升。 GPT模型的核心是一个多层Transformer解码器结构,它通过在海量的文本数据上进行预训练来学习语言的规律。这种预训练方式使得GPT模型能够捕捉到丰富的上下文信息,并生成流畅、自然的文本。 GPT模型的训练过程可以分为两个阶段: 预训练阶段:在这个阶段,模型会接触到大量的文本数据,并通过无监督学习的方式学习语言的结构和规律。具体来说,模型会尝试预测文本序列中的下一个词或短语,从而学习到语言的语法、语义和上下文信息。 微调阶段(也称为下游任务训练):在预训练完成后,模型会被应用到具体的NLP任务中,如文本分类、机器翻译、问答系统等。在这个阶段,模型会使用有标签的数据进行微调,以适应特定任务的需求。通过微调,模型能够学习到与任务相关的特定知识,并进一步提高在该任务上的性能。 GPT模型的优势在于其强大的生成能力和对上下文信息的捕捉能力。这使得GPT模型在自然语言生成、文本摘要、对话系统等领域具有广泛的应用前景。同时,GPT模型也面临一些挑战,如计算资源消耗大、训练时间长等问题。为了解决这些问题,研究人员不断提出新的优化方法和扩展模型架构,如GPT-2、GPT-3等,以进一步提高模型的性能和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值