iPad. UIBarButtonItem has an undocumented view of type UIToolbarTextButton. Huh?
Asked Answered
Y

1

1

I have an iPad app where I have a view controller that is the UIGestureRecognizerDelegate for a number of UIGestureRecognizers. I have implemented the following method of UIGestureRecognizerDelegate:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {


 // Double tapping anywhere on the screen hides/shows the toolbar
 if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] == YES) {

      if (touch.tapCount == 2) {

           self.toolbar.hidden = self.toolbar.isHidden ? NO : YES;

      } // if (touch.tapCount == 2)

 } // if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] == YES)


 // All gestures are ignored unless they happen on the fullscreen EAGLView
 if ([touch.view isKindOfClass:[EAGLView class]] == NO) {

      return NO;

 } // if ([touch.view isKindOfClass:[EAGLView class]] == NO)


 return YES;

}

My setup is a fullscreen EAGLView with a UIToolbar atop the EAGLView. There is a UIBarButtonItem on the toolbar. The idea here is that double-tapping anywhere toggles the appearance of the toolbar. All other gestures must occur on the EAGLView.

My problem is that taps directly on the UIBarButtonItem show touch.view to be the UIView subclass UIToolbarTextButton which is undocumented and can't be introspected.

Huh?

Can someone suggest a work around, preferably that uses introspective goodness of some form?

Thanks,
Doug

Thanks,

Doug

Yokel answered 1/5, 2010 at 1:18 Comment(0)
K
3

You can compute the .superview repeatedly until you reach a UIToolbar, EAGLView or nil.

Kamin answered 1/5, 2010 at 6:41 Comment(2)
Great minds think alike ;-). Yah, I actually arrived at this solution. A bit hack-ish but appears to be robust and does indeed work. I am still puzzled why the button does not expose a publicly accessible view. I was under the impression that everything visible is some flavor of a UIView. No?Yokel
@dugla: Because Apple doesn't want people to mess with the UIToolbar content directly I guess.Kamin

© 2022 - 2024 — McMap. All rights reserved.