(ios)屏幕触摸总结

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1 屏幕触控实现(单击 双击)

[self becomeFirstResponder];//允许多点互动self.view.multipleTouchEnabled=TRUE;

实现事件部分

#PRagmamark-#pragmamark touch

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//触摸开始}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{//移动}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{//结束UITouch *atouch=[touches anyObject];if(atouch.tapCount>=2)

{//双击}elseif(atouch.tapCount==1)

{//单击}

}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

}

2 手势识别(UIlabel 点击事件实现)

//设置图片的点击事件UITapGestureRecognizer *recongnizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapFrom:)];

recongnizer.numberOfTapsRequired=1;

self.img.userInteractionEnabled=YES;

[self.img addGestureRecognizer:recongnizer];

}-(void)handleTapFrom:(UITapGestureRecognizer *)recognizer{

[self updateDisplayValuesWithTip:@"tap"tapCount:1touchCount:1];

}

3 屏幕晃动实现

//AppDelegate 中实现- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

application.applicationSupportsShakeToEdit=YES;

}//或者代码中实现[[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];//ViewController 中实现下面方法- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)eventNS_AVAILABLE_IOS(3_0);

{

}- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)eventNS_AVAILABLE_IOS(3_0)

{if(event.subtype ==UIEventSubtypeMotionShake) {//摇一摇 行为}

}- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)eventNS_AVAILABLE_IOS(3_0)

{

}

4 图片滑动换页

UISwipeGestureRecognizer *recognizer;

self.img.userInteractionEnabled=YES;

recognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];

[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];

[[self img] addGestureRecognizer:recognizer];

}-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {

NSLog(@"Swipe received.");if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {

NSLog(@"swipe down");

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2.0f];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationRepeatAutoreverses:NO];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];//界面变化部分//........[UIView commitAnimations];

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航