父视图外的可点击按钮
Clickable Button outside parent view
我已附加按钮以使用此框架查看:
CGRectMake(self.view.frame.size.width - 80, -35, 60, 60)
主视图外的按钮部分不可点击...
有解决办法吗?
UIView
的外部边界无论如何都不会 clickable
。
一个选项可以像这样将 UIButton
添加到 UIWindow
:
//Calculate frame according to screen use it in button's frame
//Intializa button and add target to it
[self.view.window addSubView:yourButtonHere]
在您的主视图中,您应该添加:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (CGRectContainsPoint(button.frame, point)) {
return button;
}
return [super hitTest:point withEvent:event];
}
我已附加按钮以使用此框架查看:
CGRectMake(self.view.frame.size.width - 80, -35, 60, 60)
主视图外的按钮部分不可点击...
有解决办法吗?
UIView
的外部边界无论如何都不会 clickable
。
一个选项可以像这样将 UIButton
添加到 UIWindow
:
//Calculate frame according to screen use it in button's frame
//Intializa button and add target to it
[self.view.window addSubView:yourButtonHere]
在您的主视图中,您应该添加:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (CGRectContainsPoint(button.frame, point)) {
return button;
}
return [super hitTest:point withEvent:event];
}