IOS手势小结...

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //实例化图片视图对象
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 100, 320, 320)];
    //设置图片背景颜色
    imageView.backgroundColor=[UIColor redColor];
    //将图片视图对象添加到根视图对象上
    [self.view addSubview:imageView];
    //设置图片视图对象的一组动态图片
    imageView.animationImages=[self animationImages];
    imageView.animationDuration=2;//遍历一遍需要的时间
    imageView.animationRepeatCount=-1;//重复次数,-1表示无数次
    [imageView startAnimating];
    
    //实例化开始按钮对象,大小(100,30)位置从根视图坐标系统的原点偏移(110,440),按钮初始文字"开始"
    //按钮触发事件,didClickButton;self,按钮变量名,button
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(110, 440, 100, 30)];
    [button setTitle:@"开始" forState:UIControlStateNormal];
    button.backgroundColor=[UIColor orangeColor];
    [button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}
-(void)didClickButton:(UIButton *)button
{
    if ([button.titleLabel.text isEqualToString:@"开始"]) {
        [button setTitle:@"结束" forState:UIControlStateNormal];
        return;
    }
    [button setTitle:@"开始" forState:UIControlStateNormal];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//加载动态图片
-(NSArray *)animationImages
{
    //用来存储图片的名字,路径
    NSMutableArray *array=[NSMutableArray new];
    //程序安装包的根路径
    NSString *rootPath=[[NSBundle mainBundle]resourcePath];
    //图片文件的路径
    NSString *imageDirectiory=[rootPath stringByAppendingString:@"/ImagePackage"];
    //遍历生成40张图片路径
    for (NSInteger index=1; index<=40; index++) {
        NSString *imagePath=[imageDirectiory stringByAppendingFormat:@"/2250_3650903_179fb89ae279fae-%d(被拖移).tiff",index];
        //用文件内容初始化成一张图片
        UIImage *image=[[UIImage alloc]initWithContentsOfFile:imagePath];
        //每一张图片路径添加到数组内
        [array addObject:image];
    }
    return array;
}
@end


UIEvent,事件分三类:触摸事件/晃动事件/远程控制事件

UIResponder是基类,所有UIView派生出来的UIKit类都源自他,他继承与NSObject

第一响应者是应用程序中当前负责接受触摸事件的响应者对象.

响应者链:硬件--响应者--application--window--viewController--View.

1,在一定时间内关闭事件传递:应用程序调用UIApplication的beginIgnoringInteractionEvents和endIgnoringInteractionEvents

 2,UIGestureRecognizer  tap longTap swipe rotation pan平移 pinch捏合

 

 //实例化图像视图
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 300, 300)];
    UIImage *image=[UIImage imageNamed:@"test"];
    imageView.image=image;
    imageView.userInteractionEnabled=YES;
   //    UITapGestureRecognizer:UIGestureRecognizer               点击
   //    UISwipeGestureRecognizer:UIGestureRecognizer            轻扫
   //    UILongPressGestureRecognizer:UIGestureRecognizer      长按
   //    UIPanGestureRecognizer:UIGestureRecognizer                拖拽
   //    UIPinchGestureRecognizer:UIGestureRecognizer              捏合
   //    UIRotationGestureRecognizer:UIGestureRecognizer          翻转


    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]init];
    //点击需要的手指头个数
    [tapGesture setNumberOfTouchesRequired:1];
    //点击需要的次数
    [tapGesture setNumberOfTapsRequired:1];
    //添加手势成功识别后的动作及发送对象
    [tapGesture addTarget:self action:@selector(_tapMethods:)];
    [self.view addSubview:imageView];
   // [imageView addGestureRecognizer:tapGesture];
    
    UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc]init];
    [longPress setNumberOfTapsRequired:1];
    [longPress setNumberOfTouchesRequired:1];
     //最小识别时长
    [longPress setMinimumPressDuration:0.1];
    //设置允许的误差
    [longPress setAllowableMovement:12];
    //添加目标动作
    [longPress addTarget:self action:@selector(longMethod:)];
    [imageView addGestureRecognizer:longPress];
}
-(void)longMethod:(UILongPressGestureRecognizer *)sender
{
    NSLog(@"%s",__FUNCTION__);
}
-(void)_tapMethods:(UITapGestureRecognizer *)tap
{
    UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"温馨提示" delegate:Nil cancelButtonTitle:@"cancel" destructiveButtonTitle:@"点击" otherButtonTitles:@"Ok", nil];
    [actionSheet showInView:self.view];    
}
最后重点

如下代码有什么问题? 

UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelOnClick:)];
    tap.numberOfTapsRequired=1;
    tap.numberOfTouchesRequired=1;    
   
    self.label.userInteractionEnabled=YES;
    [self.label addGestureRecognizer:tap];
    [self.button addGestureRecognizer:tap];

-(void)labelOnClick:sender
{
    NSLog(@"label on click");
}

发现label的手势不起作用,原因有两点:

1,label默认UserInteractionEnabled为no,需要设置

[self.label setUserInteractionEnabled:YES];

2,手势对应一个事件,并且对应一个控件,如果label和button用同一个手势,只有后来使用的才会有效果.

内容概要:本文档是关于基于Tecnomatix的废旧智能手机拆解产线建模与虚拟调试的毕业设计任务书。研究内容主要包括:分析废旧智能手机拆解工艺流程;学习并使用Tecnomatix软件搭建拆解产线的三维模型,包括设备、输送装置等;进行虚拟调试以模拟各种故障情况,并对结果进行分析提出优化建议。研究周期为16周,涵盖了文献调研、拆解实验、软件学习、建模、调试和论文撰写等阶段。文中还提供了Python代码来模拟部分关键流程,如拆解顺序分析、产线布局设计、虚拟调试过程、故障模拟与分析等,并实现了结果的可视化展示。 适合人群:本任务书适用于机械工程、工业自动化及相关专业的本科毕业生,尤其是那些对智能制造、生产线优化及虚拟调试感兴趣的学生。 使用场景及目标:①帮助学生掌握Tecnomatix软件的应用技能;②通过实际项目锻炼学生的系统建模和虚拟调试能力;③培养学生解决复杂工程问题的能力,提高其对废旧电子产品回收再利用的认识和技术水平;④为后续的研究或工作打下坚实的基础,比如从事智能工厂规划、生产线设计与优化等工作。 其他说明:虽然文中提供了部分Python代码用于模拟关键流程,但完整的产线建模仍需借助Tecnomatix商业软件完成。此外,为了更好地理解和应用这些内容,建议学生具备一定的编程基础(如Python),并熟悉相关领域的基础知识。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值