0

ボタンから呼び出されるアクションシートを備えたiPadアプリを持っています。actionSheetにshowFromRectを使用しているので、popOverのように見えます。アプリを最初に起動したとき、デバイスが少なくとも1回回転するまで、actionSheetが正しい場所に表示されることはありません。デバイスを回転させた後、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];
}

どんな助けでも大歓迎です。

4

1 に答える 1

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

このメソッドは、デバイスが回転されているかどうかに関係なく、正しい位置を示します。

于 2011-02-06T15:39:27.510 に答える