Buttons/Links .xib 文件中的视图对象没有响应

Buttons/Links under view object in .xib file are not responding

有人能告诉我为什么我的 .xib 文件中 "License Agreement View" UIView 对象下的 none 个按钮触发了一个动作吗?似乎 Scrollview 对象搞乱了行为。当按钮直接位于 "Scroll View" 对象(而不是 "License Agreement View" UIView 对象)下时,它们可以正常工作。但是,我需要将我的按钮分组到 UIView 下,如下面的视图层次结构所示。

视图布局如下:

这是我的视图层次结构:

对应的.m文件如下:

@interface MYViewController ()
     - (IBAction)licenseAgreementPressed:(id)sender;
     - (IBAction)legalDisclaimerPressed:(id)sender;
     - (IBAction)privacyStatementPressed:(id)sender;

     @property (strong, nonatomic) IBOutlet UIView *licenseAgreementView;
     @property (weak, nonatomic) IBOutlet UIButton *legalDisclaimerButton;
     @property (strong, nonatomic) IBOutlet UIButton *privacyStatementButton;
@end

@implementation MYViewController
- (IBAction)licenseAgreementPressed:(id)sender
{
     NSLog(@"Pressed A");
}

- (IBAction)legalDisclaimerPressed:(id)sender
{
     NSLog(@"Pressed B");
}

- (IBAction)privacyStatementPressed:(id)sender 
{
     NSLog(@"Pressed C");
}
@end

请确保您已将 IBAction(code) 和 UIButton(in xib) 连接起来,请检查此 post How do I name and link an IBAction button created in a storyboard

您是否通过 control-dragging 将您的操作连接到界面生成器中的元素? 如果您的操作已连接,您将在编辑器中的行左侧看到一个填充的小圆圈。 查看 this tutorial 了解有关如何将故事板元素连接到代码的更多信息。

这是因为 none 个按钮 在许可协议视图的范围内 。超出父视图边界的按钮不可点击。

所以问题是链接、按钮和文本字段实际上并未位于指定父视图的范围内,因为原始 .xib 文件没有将所需的约束固定到这些元素。我通过选中“属性检查器”窗格中的 "clip to bounds" 复选框发现了这一点。每当检查 "clip to bounds" 时,应用程序都不会显示上述任何视图对象;当 "clip to bounds" 未选中时,我只能看到链接、按钮和文本字段,但不幸的是,这些元素此时不可点击。然而,在设置必要的约束后,视图元素被正确地放置在它们父视图的边界内,并且文本字段、标签和按钮变得可点击。我附上了我用来解决问题的约束。注意:不展开的约束只包括高度约束。