Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you like to use <a href="https://stackoverflow.com/questions/3000681/what-are-private-apis">private API</a>s? If yes,</p> <pre><code>UIView* view = thatItem.view; return [view convertRect:view.bounds toView:nil]; </code></pre> <hr> <p>Of course no one wants this when targeting the AppStore. A <strong>more unreliable</strong> method, and also uses undocumented features, but will pass Apple's test, is to loop through the subviews to look for the corresponding button item. </p> <pre><code>NSMutableArray* buttons = [[NSMutableArray alloc] init]; for (UIControl* btn in theToolbarOrNavbar.subviews) if ([btn isKindOfClass:[UIControl class]]) [buttons addObject:btn]; UIView* view = [buttons objectAtIndex:index]; [buttons release]; return [view convertRect:view.bounds toView:nil]; </code></pre> <p>The <code>index</code> is the index to your bar item in the array of <code>.items</code>, <em>after removing all blank items</em>. This <em>assumes</em> the buttons are arranged in increasing order, which may not be. A more reliable method is to <em>sort</em> the <code>buttons</code> array in increasing <code>.origin.x</code> value. Of course this still <em>assumes</em> the bar button item must inherit the UIControl class, and are direct subviews of the toolbar/nav-bar, which again may not be. </p> <hr> <p>As you can see, there are a lot of uncertainty when dealing with undocumented features. However, you just want to pop up something under the finger right? The UIBarButtonItem's <code>.action</code> can be a selector of the form:</p> <pre><code>-(void)buttonClicked:(UIBarButtonItem*)sender event:(UIEvent*)event; </code></pre> <p>note the <em>event</em> argument — you can obtain the position of touch with</p> <pre><code>[[event.allTouches anyObject] locationInView:theWindow] </code></pre> <p>or the button view with</p> <pre><code>[[event.allTouches anyObject] view] </code></pre> <p>Therefore, there's no need to iterate the subviews or use undocumented features for what you want to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload