ios - UIButton in subview not receiving touch after NSLayoutConstraint -
i have 2 custom uiviews i'm adding uiviewcontroller , aligning them using nslayoutconstraint. after apply nslayoutconstraint on uiviewcontroller view uibuttons in custom uiviews no longer receive touch events.
- (void)viewdidload { [super viewdidload]; navigationbar = [[dtnavigationbar alloc] initwithframe:cgrectmake(0,0,320,45)]; [navigationbar settranslatesautoresizingmaskintoconstraints:no]; [self.view addsubview:navigationbar]; switchbar = [[dtswitch alloc] initwithframe:cgrectmake(0,0,320,44)]; [switchbar settranslatesautoresizingmaskintoconstraints:no]; [self.view addsubview:switchbar]; [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|-0-[navigationbar(45)]-0-[switchbar(44)]-(>=100)-|" options:nslayoutformatalignallleft metrics:nil views:nsdictionaryofvariablebindings(switchbar, navigationbar)]]; }
both dtnavigationbar , dtswitch have uibutton views still show in right place no longer responds touch.
if remove addconstraints part (and manually place views) buttons work fine.
the problem that, having elected use constraints, not using enough constraints. have ambiguous layout.
to test hypothesis, run app, , pause in debugger , enter in lldb console:
po [[uiwindow keywindow] _autolayouttrace]
the words ambiguous layout appear somewhere in response.
you need sufficient constraints make words go away. must determine vertical , horizontal position and width and height of in story.
Comments
Post a Comment