Not sure if you need UIButton. If what you are doing is submitting an action or even customizing a button with an image, you need UIBarButtonItem
.
If you want to capture a frame from UIButton
in order to achieve a presentation, I think you'd better just evaluate the position of the UIBarButtonItem
. This should not be too complicated, especially if it is one or the other of your UINavigationItem
leftBarButtonItem
or rightBarButtonItem
.
I usually use the KISS (Keep It Simple, Stupid!) Rule. Even Apple does this ... when starting an application from Springboard, the application always expands from the center of the screen, and not from the application icon.
Just an offer.
EDIT
OK, I just read the UIPopoverController link (I never used it). I think you want presentPopoverFromBarButtonItem:permittedArrowDirections:animated:
and pass your BBI as the first parameter. The reason this method exists is to solve your problem - BBIs do not have a frame because they are not subclasses of NSView. Apple knows that you want to do this, and provides this method. In addition, I think that if you use this method, your autorotation will also work. Maybe I'm wrong, give him a chance.
As for your customized layout, I think that if you play it in a UIView and configure BBI with this, you will do better. This, of course, is up to you.
In any case, you get a link to the BBI, either by connecting it as an IBOutlet with your NIB, or by storing the link to it when you create it in code. Then just pass this link to the popover method described above. I think this might work for you.
Moar
BBI is just a member of your class - iVar with a strong reference property on it, possibly related as an IBOutlet to your NIB. Then you can access it from any method you want in the class.
Example: (not sure if I am managing popover controller memory correctly)
@interface MyViewController : UIViewController { UIBarButtonItem *item; } @property (nonatomic, retain) UIBarButtonItem *item; @end @implementation MyViewController @synthesize item; -(void)viewDidLoad {