title: UIPopoverController Appears in Wrong Spot
body: <p>So I've spent some time looking for an answer for this, but so far haven't found anything.</p>
  
  <p>I'm trying to present a popover from a button on an UIInputAccessoryView. The UIBarButtonItem i want to display the popover from has a custom view so I can use an image. I create the button like this:</p>
  
  <pre><code> buttonImage=[UIImage imageNamed:@"tags.png"];
   aButton=[UIButton buttonWithType:UIButtonTypeCustom];
   [aButton setImage:buttonImage forState:UIControlStateNormal];
   aButton.frame=CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
   UIBarButtonItem* compButton2=[[UIBarButtonItem alloc]initWithCustomView:aButton];
   [aButton addTarget:self action:@selector(tagIt:) forControlEvents:UIControlEventTouchUpInside];
  </code></pre>
  
  <p>When it comes time to display the popover, I do it like this:</p>
  
  <pre><code>CGRect tRect=[((UIButton*)sender) convertRect:((UIButton*)sender).frame toView:self.notePlainText];
  NSLog(@"TagIt tRect: %f %f %f %f", tRect.origin.x, tRect.origin.y, tRect.size.width, tRect.size.height);
  [self.popoverController presentPopoverFromRect:tRect inView:self.notePlainText permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  </code></pre>
  
  <p>But what I get is this:</p>
  
  <p><img src="https://i.stack.imgur.com/W8y1y.png" alt="enter image description here"></p>
  
  <p>The popover looks fine, but it appears over the second button when it should be appearing over the first.</p>
  
  <p>So then I found this question: <a href="https://stackoverflow.com/questions/2681321/uibarbuttonitem-with-custom-image-and-no-border">UIBarButtonItem with custom image and no border</a> and I thought, "ah, perhaps it will work better if I present the popover from a barbuttonitem instead of doing it this way. The code sub classes UIBarButtonItem in order to have a button with an image, not text, and represents the barbuttonitem properly when the action is called. This allowed me to use ...presentPopoverFromBarButtonItem...</p>
  
  <p>So I tried the code in the second answer in the aforementioned question, and got a result that was better. The popover points right to the button as I wanted, but if the orientation of the device is not portrait with the button on the bottom, the popover displays with the wrong orientation:</p>
  
  <p><img src="https://i.stack.imgur.com/TTVGy.png" alt="Popover with wrong orientation"></p>
  
  <p>Finally, I will point out that I have other bar button items elsewhere in the program that are not in UIInputAccessoryViews that come up properly and without issue. It only seems to be happening form the input accessory view.</p>
  
  <p>This just in: Hiding and showing the keyboard seems to make this work a bit better. Looking at the frame (CGRect) data for the button, it doesn't change between rotations unless it's hidden and brought back. Is this a bug?</p>
  
  <p>So.. my question is this: what is the preferred, best-practices way of presenting a popover from a bar button item embedded in a ui accessory view?</p>
  
  <p>Thank you very much.</p>