VBFPopFlatButton as UIBarButtonItem
Closed this issue · 7 comments
Hi, when I added VBFPopFlatButton as UIBarButtonItem, the all touches are not recognized from first time – it's very bad triggered.
My try was in that way:
self.addTaskButton = [[VBFPopFlatButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25) buttonType:buttonAddType buttonStyle:buttonPlainStyle animateToInitialState:YES];
self.addTaskButton.lineThickness = 2;
self.addTaskButton.tintColor = [UIColor whiteColor];
[self.addTaskButton addTarget:self
action:@selector(addTask)
forControlEvents:UIControlEventTouchUpInside];
UIView *containingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
// UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addTask)];
// [containingView addGestureRecognizer:singleFingerTap];
[containingView addSubview:self.addTaskButton];
UIBarButtonItem *containingBarButton = [[UIBarButtonItem alloc] initWithCustomView:containingView];
self.navigationItem.rightBarButtonItem = containingBarButton;
Then I tried to make containing view tappable and increase its area but this didn't help.
I know that UIButton and UIBarButtonItem are the different things but maybe someone could help me to make VBFPopFlatButton work as normal default UIBarButtonItem and make it excellent triggering? Thanks.
@sashakid why are you adding it in a containingView
? You shouldn't need to do that. The following works on my app:
self.leftButton = [[VBFPopFlatButton alloc] initWithFrame:CGRectMake(0, 0, BONavButtonWidth, BONavButtonHeight) buttonType:buttonBackType buttonStyle:buttonPlainStyle animateToInitialState:NO];
[self.leftButton addTarget:self action:@selector(collapseSplitView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *collapseButton = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
self.navigationItem.leftBarButtonItem = collapseButton;
Thanks for your answer @MattKiazyk
I haven't had time to try it as a UIBarButtonItem
Nice one!!
@MattKiazyk I have explained the reason in my comment: it's because of bugs with touches. In simulator it works OK, but it's very buggy on the device. Have you tried it on the device? @victorBaro could you, please, keep the issue opened until it will be well-tested?
@sashakid did you try not adding it to a view first? so in your case:
UIBarButtonItem *containingBarButton = [[UIBarButtonItem alloc] initWithCustomView:self.addTaskButton];
self.navigationItem.rightBarButtonItem = containingBarButton;
@MattKiazyk you're right, I've just tested it on the device. It works fine, but there were magic for me a few months ago because I've tried to add VBFPopFlatButton in usual way, like you suggested, and in containing view - and in both ways it was buggy. So, thanks for help! :-)