UITapGestureRecognizer单击和双击事件响应
如果tap事件定义在同一个地方的通用方法是下面:
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease];
singleTap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:singleTap];
UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)] autorelease];
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
[singleTap requireGestureRecognizerToFail:doubleTap];
但是如果子类的tap事件定义在别处,上面方法就比较麻烦了。就可以使用代理来解决这个问题.UIGestureRecognizerDelegate
。这边假设doubleTap定义在子类,singleTap定义在父类,则由于代理的效果先响应doubleTap
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[self.view addGestureRecognizer:singleTap];
//该方法返回YES,则就可以实现先响应别的方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
UIViewController如何背景透明
通过设置modalPresentationStyle来实现,iOS8以前和iOS8以后方法不一样
if (IsGreaterIOS8) {
_browser.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}else{
_browser.modalPresentationStyle = UIModalPresentationCurrentContext;
}
常用到的常量定义
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define IsGreaterIOS8 SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")