I have an UIToolbar with several UIBarButtonItems. I'm currently trying to implement a custom animation for which I need a starting point. This animation is triggered with click on one of the toolbar's items, namely plusIcon
.
The animation works, but I haven't been able to get a CGPoint for the UIBarButtonItem.
Browsing the web I found the following for a navigationBar (unfortunately in Objective-C):
- (void)handleItemPressed {
UIView *targetView = nil;
for (UIView *subView in self.navigationController.navigationBar.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
for (UILabel *label in subView.subviews) {
if ([label isKindOfClass:[UILabel class]]) {
if ([label.text isEqualToString:"right"]) {
targetView = subView;
break;
}
}
}
}
}
CGRect rect = [targetView convertRect:targetView.frame toView:self.view];
CGPoint center_you_need = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
}
I tried to convert this code for my desires, but I don't think this suits my problem - if it does, please correct me.
I've also tried the following, to get to the position of iconPlus
:
btnPos = CGPoint(x: toolbar.center.x + (toolbar.center.x / 2) + (toolbar.center.x / 6), y: toolbar.center.y + 5)
This one works, but only on the iPhone X - on other devices, toolbar.center
somehow won't return the actual center of the toolbar.
Any suggestion, any ideas how to get a UIBarButtonsItem
's position?