2011-02-06 2 views
0

버튼에서 호출되는 작업 시트가있는 iPad 앱이 있습니다. Im는 actionSheet에 showFromRect를 사용하여 popOver처럼 보입니다. 앱이 처음 시작될 때 actionSheet는 기기가 적어도 한 번 이상 회전 할 때까지 정확한 위치에 표시되지 않습니다. 장치가 회전 된 후 actionSheet가 올바른 위치에 있습니다. 내 코드는 아래 있습니다.iPad가 적어도 한 번 회전 할 때까지 올바르게 표시되지 않는 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

첫 번째 off UIDeviceOrientation은 UIInterfaceOrientation과 다릅니다. 왼쪽 및 오른쪽 방향이 반전되므로 홈 버튼이 왼쪽에있을 때 UIInterfaceOrientationLeft에 있지만 UIDeviceOrientationRight에도 있습니다. – Rich

+0

둘째, 현재 뷰에서 rect가 그려지면 뷰의 좌표계에 그려집니다. 보기가 전체 화면이 아닌 경우 예상 한 위치에 표시되지 않을 수 있습니다. – 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]; 
} 

이 방법은 장치가 회전되었는지 여부에 관계없이 정확한 위치를 보여줍니다.