如标题,使用initWithFrame生成的UIView,backgroundColor默认的opaque是0,若不修改这个opaque,其无法接收到各种gesture,测试代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect rectScr=[UIScreen mainScreen].bounds;
UIWindow *window=[[UIWindow alloc] initWithFrame:rectScr];
UIViewController *vc=[[UIViewController alloc] init];
myView *view=[[myView alloc] initWithFrame:rectScr]; //myView类继承了UIView类,且自带了UITapGestureRecognizer的响应函数
view.backgroundColor=[UIColor colorWithRed:0 green:0.3 blue:0 alpha:1]; //一定要带上这句,否则默认的 alpha是0,代表view是透明的,本view接收不到手势事件
vc.view=view;
window.rootViewController=vc;
self.window=window;
return YES;
}