iPad App using ActionSheet showing fromRect which doesn't show correctly until the device is rotated at least once

2k views Asked by At

I have an iPad app, which has a action sheet called from a button. Im using the showFromRect for the actionSheet so it looks like a popOver. When the app first starts up the actionSheet never shows in the correct place until after the device is rotated at least once. After the device is rotated the actionSheet is in the correct place. my code is below.

-(IBAction)showMenu
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Copy To The Clipboard" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Term & Definition",@"Term",@"Definition", nil];

UIDevice *thisDevice = [UIDevice currentDevice];
CGRect myImageRect;

if(thisDevice.orientation==UIDeviceOrientationPortrait){myImageRect = CGRectMake(300.0f, 950.0f, 320.0f, 175.0f);NSLog(@"P");}  //Portait Mode
else if(thisDevice.orientation==UIDeviceOrientationPortraitUpsideDown){myImageRect = CGRectMake(300.0f, 950.0f, 320.0f, 175.0f);NSLog(@"PUD");}//Portait Mode UpsideDown
else if(thisDevice.orientation==UIDeviceOrientationLandscapeLeft){myImageRect = CGRectMake(300.0f, 700.0f, 320.0f, 175.0f);NSLog(@"LL");}//Landscape Mode Left
else if(thisDevice.orientation==UIDeviceOrientationLandscapeRight){myImageRect = CGRectMake(300.0f, 700.0f, 320.0f, 175.0f);NSLog(@"LR");}//Landscape Mode Right

[actionSheet showFromRect:myImageRect inView:self.view animated:YES];
[actionSheet release];
}

any help would greatly be appreciated.

1

There are 1 answers

0
OscarTheGrouch On BEST ANSWER
-(IBAction)pasteMenuiPad
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Copy To The Clipboard" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Term & Definition",@"Term",@"Definition", nil];

    CGRect myImageRect = CGRectMake(300.0f, 950.0f, 320.0f, 175.0f);;

    if([self interfaceOrientation] == UIInterfaceOrientationPortrait){myImageRect = CGRectMake(300.0f, 950.0f, 320.0f, 175.0f);NSLog(@"P");}    //Portait Mode
    else if([self interfaceOrientation] == UIInterfaceOrientationPortraitUpsideDown){myImageRect = CGRectMake(300.0f, 950.0f, 320.0f, 175.0f);NSLog(@"PUD");}//Portait Mode UpsideDown
    else if([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft){myImageRect = CGRectMake(300.0f, 700.0f, 320.0f, 175.0f);NSLog(@"LL");}//Landscape Mode Left
    else if([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight){myImageRect = CGRectMake(300.0f, 700.0f, 320.0f, 175.0f);NSLog(@"LR");}//Landscape Mode Right

    [actionSheet showFromRect:myImageRect inView:self.view animated:YES];
    [actionSheet release];
}

This method shows the correct positioning whether or not the device has been rotated.