Reputation: 2713
I have MasterChatViewController
in which I added as a subview a custom UIView called JFShapedNavBar
. Inside the JFShapedNavBar
I added a subview of UIButton
with an image and added a target-action to a method that just prints something to the console in order to debug right now.
MasterChatViewController
contains JFShapedNavBar
and
JFShapedNavBar
contains UIButton
.
I use Masonry
to setup constraints. When I initialize the views I use a custom variant of initWithFrame:CGRectZero
:
_shapedNavBar = [[JFShapedNavBar alloc] initWithFrame:CGRectZero
forViewController:self];
[self.view addSubview:_shapedNavBar];
[_shapedNavBar mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.equalTo(self.view);
}];
Inside the JFShapedNavBar.m
:
-(void)configureRightButton {
// Right Button of Nav
UIImage *buttonImage = [UIImage imageNamed:@"LobbyButton"];
_rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rightButton setImage:buttonImage forState:UIControlStateNormal];
[_rightButton addTarget:self action:@selector(testTouch) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_rightButton];
[self setNeedsUpdateConstraints];
}
-(void)testTouch {
NSLog(@"You managed to figure out what you were doing wrong.");
}
-(void)updateConstraints {
[super updateConstraints];
[_arcShadow mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self);
make.height.equalTo(__navHeight);
}];
[_arcDrop mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_arcShadow);
make.height.equalTo(_arcShadow.mas_height);
}];
[_rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(24);
make.trailing.equalTo(self).offset(-16);
make.height.equalTo(@30);
}];
}
Ultimately, I am attempting to create a custom navigation bar (but not a subclass of the one in UIKit). I experimented for approximately 2 hours trying to figure out why the target-action handler doesn't fire, but now I am frustrated and out of ideas. Why can I not touch the UIButton?
Maybe this matters, I don't know, but on my view controller MasterChatViewController
I have set hidden the navigation bar self.navigationController.navigationBarHidden = YES;
Upvotes: 0
Views: 1806
Reputation: 1231
This won't solve your problem, but just some standard things to do for debugging tappable issues
1) temporarily set the background of all the buttons to green (so that you can see where their hit areas extend to
2) set userInteraction = YES on the children, and superview containers (sometimes)
3) look out for any gesture recognizer that may be swallowing your touches
4) make sure the button that is inside of the container view is inside of its bounds.. if its not, it wont be tappable
5) To further investigate layout issues, use Reveal or xcodes built in rip off of it for view debugging http://www.raywenderlich.com/98356/view-debugging-in-xcode-6
Upvotes: 3