//把bgView强制修改成UIControl,以便响应触摸事件
//UIControl是UIView的子类

//其实有很多情况都可以这样用,用一个普通的UIView来模拟某些控件,可以很灵活!!!!

 

UIView *bgView;


CGRect bgFrame = CGRectMake(0.0, 35.0, 320.0, 460.0 - 35.0);
UIControl *bgControl = [[UIControl alloc] initWithFrame:bgFrame];
[bgControl addTarget:self
action:@selector(resignKeyboardAction)
forControlEvents:UIControlEventTouchDown];
self.bgView = bgControl;
[bgControl release];
self.bgView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.bgView.hidden = YES;
[self.view addSubview:bgView];

相关文章:

  • 2022-02-04
  • 2021-10-11
  • 2022-02-15
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-07-07
  • 2021-09-06
  • 2021-11-17
  • 2021-08-12
相关资源
相似解决方案