0

我有一个 iPad 应用程序,它有一个从按钮调用的操作表。我将 showFromRect 用于 actionSheet,所以它看起来像一个 popOver。当应用程序第一次启动时,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 回答