标签:style blog http color 使用 os io for
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)remoteControlReceivedWithEvent:(UIEvent *)event;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
提示:touches中存放的都是UITouch对象
- (CGPoint)locationInView:(UIView *)view;
- (CGPoint)previousLocationInView:(UIView *)view;
@property(nonatomic,readonly) UIEventType type; @property(nonatomic,readonly) UIEventSubtype subtype;
@property(nonatomic,readonly) NSTimeInterval timestamp;
UIApplication -> UIWindow -> 白色 -> 绿色
UIApplication -> UIWindow -> 白色 -> 橙色 -> 蓝色
UIApplication -> UIWindow -> 白色 -> 橙色 -> 蓝色 -> 黄色
userInteractionEnabled = NO
hidden = YES
alpha = 0.0 ~ 0.01
提示:UIImageView的userInteractionEnabled默认就是NO,因此UIImageView以及它的子控件默认是不能接收触摸事件的
响应者链条示意图:
#pragma mark - 手势识别器的代理方法 /** * 是否允许多个手势识别器同时有效 * Simultaneously : 同时地 */ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
Ø创建手势识别器对象 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; Ø设置手势识别器对象的具体属性 // 连续敲击2次 tap.numberOfTapsRequired = 2; // 需要2根手指一起敲击 tap.numberOfTouchesRequired = 2; Ø添加手势识别器到对应的view上 [self.iconView addGestureRecognizer:tap]; Ø监听手势的触发 [tap addTarget:self action:@selector(tapIconView:)];
#pragma mark - 缩放手势(捏合手势) - (void)testPinch { UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)]; pinch.delegate = self; [self.iconView addGestureRecognizer:pinch]; } - (void)pinchView:(UIPinchGestureRecognizer *)pinch { pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale); pinch.scale = 1; // 这个真的很重要!!!!! }
- (void)viewDidLoad { [super viewDidLoad]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)]; [self.purpleView addGestureRecognizer:pan]; } - (void)panView:(UIPanGestureRecognizer *)pan { switch (pan.state) { case UIGestureRecognizerStateBegan: // 开始触发手势 break; case UIGestureRecognizerStateEnded: // 手势结束 break; default: break; } // 1.在view上面挪动的距离 CGPoint translation = [pan translationInView:pan.view]; CGPoint center = pan.view.center; center.x += translation.x; center.y += translation.y; pan.view.center = center; NSLog(@"%@",NSStringFromCGPoint(translation)); // 2.清空移动的距离 [pan setTranslation:CGPointZero inView:pan.view]; }
4>UISwipeGestureRecognizer(轻扫)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeView)]; swipe.direction = UISwipeGestureRecognizerDirectionUp; [self.redView addGestureRecognizer:swipe];
#pragma mark - 旋转手势 - (void)testRotate { UIRotationGestureRecognizer *recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)]; recognizer.delegate = self; [self.iconView addGestureRecognizer:recognizer]; } - (void)rotateView:(UIRotationGestureRecognizer *)recognizer { recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation); recognizer.rotation = 0; // 这个很重要!!!!! }
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] init]; [longPress addTarget:self action:@selector(longPressView)]; // 至少长按2秒 longPress.minimumPressDuration = 2; // 在触发手势之前,50px范围内长按有效 longPress.allowableMovement = 50; [self.redView addGestureRecognizer:longPress];
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { // 没有触摸事件发生,所有手势识别的默认状态 UIGestureRecognizerStatePossible, // 一个手势已经开始但尚未改变或者完成时 UIGestureRecognizerStateBegan, // 手势状态改变 UIGestureRecognizerStateChanged, // 手势完成 UIGestureRecognizerStateEnded, // 手势取消,恢复至Possible状态 UIGestureRecognizerStateCancelled, // 手势失败,恢复至Possible状态 UIGestureRecognizerStateFailed, // 识别到手势识别 UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded };
标签:style blog http color 使用 os io for
原文地址:http://www.cnblogs.com/lszwhb/p/3918106.html