银幕触摸事件,摇一摇晃动事件
屏幕触摸事件,摇一摇晃动事件
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(@"内存警告");
}
版权声明:本文为博主原创文章,未经博主允许不得转载。