本文主要是介绍ios开发——手势识别(Screen Edge Pan),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#import "ViewController.h"@interface ViewController ()
@property(strong, nonatomic) UILabel *label;
@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//初始化界面CGRect screen = [[UIScreen mainScreen] bounds];CGFloat labelWidth = 300;CGFloat labelHeight = 30;CGFloat labelTopView = 150;CGRect frame = CGRectMake((screen.size.width - labelWidth) / 2, labelTopView, labelWidth, labelHeight);self.label = [[UILabel alloc] initWithFrame:frame];self.label.text = @"屏幕边缘平移手势识别";//字体左右居中self.label.textAlignment = NSTextAlignmentCenter;[self.view addSubview:self.label];//创建2个ScreenEdgePan手势识别器NSInteger edges[2] = {UIRectEdgeRight, UIRectEdgeLeft};for (int i = 0; i < 2; i++) {UIScreenEdgePanGestureRecognizer *recognizer = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:selfaction:@selector(foundScreenEdgePan:)];//设置识别边缘平移方向recognizer.edges = edges[i];//ScreenEdgePan手势识别器关联到View[self.view addGestureRecognizer:recognizer];}//设置View开启用户事件self.view.userInteractionEnabled = YES;
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];
}- (void)foundScreenEdgePan:(UIScreenEdgePanGestureRecognizer*)sender {NSLog(@"edge = %li", (unsigned long)sender.edges);switch (sender.edges) {case UIRectEdgeLeft:self.label.text = @"从左边缘向右平移";break;case UIRectEdgeRight:self.label.text = @"从右边缘向左平移";break;default:self.label.text = @"";}
}@end
这篇关于ios开发——手势识别(Screen Edge Pan)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!