本文實例為年夜家分享了IOS完成閣下滑動操作代碼,供年夜家參考,詳細內容以下
1、後果圖
2、代碼
RootViewController.m
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"可以向左(右)滑動"; //向右滑動 UISwipeGestureRecognizer *recognizerLeft; recognizerLeft = [[UISwipeGestureRecognizer alloc] initWithtarget:self action:@selector(handleSwipeFromLeft:)]; [recognizerLeft setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [self.view addGestureRecognizer:recognizerLeft]; //向左滑動 UISwipeGestureRecognizer *recognizerRight; recognizerRight = [[UISwipeGestureRecognizer alloc] initWithtarget:self action:@selector(handleSwipeFromRight:)]; [recognizerRight setDirection:(UISwipeGestureRecognizerDirectionRight)]; [self.view addGestureRecognizer:recognizerRight]; } #pragma -mark -手勢滑動 //向左滑動 -(void)handleSwipeFromLeft:(UISwipeGestureRecognizer *)recognizer { NSLog(@"-------進入向左手勢滑動姿態-------------"); if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"進入向左手勢滑動姿態" delegate:self cancelButtonTitle:@"撤消" otherButtonTitles:@"肯定", nil]; [alert show]; } } //向右滑動 -(void)handleSwipeFromRight:(UISwipeGestureRecognizer *)recognizer { NSLog(@"-------進入向右手勢滑動姿態-------------"); if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"進入向右手勢滑動姿態" delegate:self cancelButtonTitle:@"撤消" otherButtonTitles:@"肯定", nil]; [alert show]; } }
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐本站。
【IOS代碼筆記之閣下滑動後果】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!