ios新手必看之手势
来源:互联网 发布:淘宝手机怎么删除差评 编辑:程序博客网 时间:2024/05/21 13:59
// 自定义视图
// 视图可以通过从写Touch方法实现响应点击
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
@property (nonatomic,assign)CGFloat myPoint;
@end
self.view.backgroundColor = [UIColorwhiteColor];
UIView *view = [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
// 设置Tag标记
view.tag = 100;
view.backgroundColor = [UIColoryellowColor];
[self.viewaddSubview:View];
[view release];//MRC不要忘了释放
}
//释放
- (void)dealloc {
[super dealloc];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"触摸开始");
// 实现清扫屏幕(实例)
UITouch *touch = [touches anyObject];
CGPoint point = [touch1 locationInView:self.view];
_myPoint = point.x;
// label.userInteractionEnabled = YES;//打开交互
// ui里面有辆特殊的view—UILabel(标签), UIImageVIew(图片),这两视图默认没有交互,就是默认完全不响应用户事件的。
/*
响应者链的顺序,从底层向上层寻找,找到发生时间的对象,然后依次向底层处理。响应者链可以阻断。(userInteractionEnabled),它会逐层返回至Application,系统确认为无效事件并销毁完成整个过程。
*/
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"触摸取消");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"触摸结束");
//// 获取视图通过Tag值
// UIView *view = (UIView *)[self.view viewWithTag:100];
//// 定义touch从集合取出
// UITouch *touch = [touches anyObject];
//// 通过touch获取相对于父视图的位置
// CGPoint point = [touch locationInView:self.view];
//// 设置中心点
// view.center = point;
// 清扫
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
if (point.x -_myPoint >= 200 ) {
UIView *view = (UIView *)[self.viewviewWithTag:100];
[view removeFromSuperview];//删除view实现清扫
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"正在触摸");
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"摇一摇开始");
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"摇一摇结束");
// 实现摇一摇换色
UIView *view = (UIView *)[self.viewviewWithTag:100];
view.backgroundColor = [UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0blue:arc4random()%256/255.0alpha:0.8];
}
@end
- ios新手必看之手势
- iOS新手必看之全貌
- iOS新手必看之全貌
- 新手必看之UILabel
- XML解析之Digester(新手必看)
- XML解析之Degister(新手必看)
- XML解析之Degister(新手必看)
- 新手必看:一步到位之InnoDB
- 新手必看:一步到位之InnoDB
- iOS-上架APP之启动页设置(新手必看!)
- IOS-上架APP之启动页设置(新手必看!)
- 新手必看(转)
- 新手必看
- 新手必看
- Ajax新手必看
- PHP新手必看
- iOS开发-小白(新手)必看,基础常识
- Java新手必看之Hello World 攻略
- UICollectionView
- 大学生就业那些事——招聘会感想
- 嵌入式linux学习笔记(一)
- [BZOJ1878] [SDOI2009]HH的项链
- UML第八集
- ios新手必看之手势
- 软件开发文档总结
- HDU 5510 KMP
- Parse教程三(利用Parse进行本地数据保存与使用)
- Timer与TimerTask的真正原理&使用介绍
- NSCalendar
- 统一管理程序异常
- Java Notes-13(Oberver, Sockets)
- Triangle