首页 > 其他 > 详细

屏幕触摸事件,摇一摇晃动事件

时间:2015-08-03 21:03:01      阅读:188      评论:0      收藏:0      [点我收藏+]
UIView支持触摸事件(因为继承于UIResponder),?而且?支持多 点触摸。
需要定义UIView?子类,实现触摸相关的?方法。

1.建立根视图控制器
原代码:

 // 设置根视图控制器
    MainViewController *mainVC=[[MainViewController alloc] init];
    _window.rootViewController =mainVC;
    [mainVC release];

在根视图上可以实现触摸的四个方法:

原代码:

1.-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸开始"); 
}
2.-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸结束");
}
3.-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸被取消");
}
4.-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸移动");
}

摇一摇晃动事件,三个方法:

hardview中 shake Gestrue 模拟摇一摇

// 摇一摇
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"摇一摇开始");
    self.view.backgroundColor =[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:0.5]; 
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"摇一摇结束");
}
-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"摇一摇被取消");
}

hardview 中Simulate Memory Warning 模拟内存管理

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"内存警告");
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

屏幕触摸事件,摇一摇晃动事件

原文:http://blog.csdn.net/mltianya/article/details/47261193

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!