我已将 a 添加UIView
到视图控制器的视图中。说:
CGRect paneRect = {10.0f, 10.0f, 300.0f, 50.0f};
UIView *pane = [[UIView alloc] initWithFrame:paneRect];
pane.backgroundColor = [UIColor greenColor];
pane.userInteractionEnabled = YES;
pane.clipsToBounds = NO;
[self.view addSubview:pane];
然后我添加了一个 UIButton 到pane
:
CGRect testRect = {10.0f, 25.0f, pane.frame.size.width - 20.0f, 50.0f};
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:@"test" forState:UIControlStateNormal];
[test setFrame:testRect];
[pane addSubview:test];
现在“测试”按钮的一半在窗格内,另一半不在。上半部分是交互式的,对触摸有反应,但下半部分不是。
是否有可能使整个“测试”按钮交互和可触摸而不是它的一半?