(ios) 屏幕觸摸總結

1  屏幕觸控實現(單擊 雙擊)app

  [self becomeFirstResponder];
     //容許多點互動
     self.view.multipleTouchEnabled=TRUE;

實現事件部分ui

#pragma mark-
#pragma mark 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)
    {
        //雙擊
    }
    else if(atouch.tapCount==1)
    {
    
       //單擊
    }
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{


}

2 手勢識別(UIlabel 點擊事件實現)url

  //設置圖片的點擊事件
    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:1 touchCount:1];
}

 

 

3 屏幕晃動實現spa

//AppDelegate 中實現
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    application.applicationSupportsShakeToEdit = YES;
}

//或者代碼中實現
 [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];

//ViewController 中實現下面方法

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
{

}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0)
{
    if (event.subtype == UIEventSubtypeMotionShake) {
        
        //搖一搖 行爲
         
    }
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0)
{

} 

 4 圖片滑動換頁code

 

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];
    }
}
相關文章
相關標籤/搜索