2011-02-06 3 views
0

ボタンから呼び出されたアクションシートを持つiPadアプリがあります。私はactionSheetのためにshowFromRectを使用するので、popOverのように見えます。アプリが最初に起動するとき、デバイスが少なくとも1回回転されるまで、actionSheetは決して正しい場所に表示されません。デバイスが回転した後、actionSheetは正しい場所にあります。私のコードは以下の通りです。iPadが少なくとも1回回転するまで正しく表示されないfromRectを示すActionSheetを使用しています

-(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]; 
} 

ご協力いただけると助かります。

+0

最初にオフのUIDeviceOrientationはUIInterfaceOrientationとは異なります。左と右の向きが反転されるので、ホームボタンが左にあるときはUIInterfaceOrientationLeftにあるだけでなく、UIDeviceOrientationRightにもあります。 – Rich

+0

第2に、現在のビューで矩形が描画されている場合、そのビューの座標系に描画されます。したがって、ビューがフルスクリーンでない場合は、表示されないことがあります。 – Rich

+0

デバイスが回転した後、それが予想される場所に表示されます。下記のソリューションを参照してください。 – OscarTheGrouch

答えて

1
-(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]; 
} 

この方法は、デバイスが回転しているかどうかにかかわらず、正しい位置を示しています。