2011-02-06 2 views
0

J'ai une application iPad, qui a une feuille d'action appelée à partir d'un bouton. Im en utilisant le showFromRect pour la feuille d'action afin qu'il ressemble à un popOver. Lorsque l'application démarre pour la première fois, la feuille d'action ne s'affiche jamais au bon endroit tant que le périphérique n'a pas été pivoté au moins une fois. Après la rotation de l'appareil, la feuille d'action est au bon endroit. mon code est ci-dessous.Application iPad utilisant ActionSheet montrant fromRect qui ne s'affiche pas correctement jusqu'à ce que l'appareil soit pivoté au moins une fois

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

toute aide serait grandement appréciée.

+0

Tout d'abord, UIDeviceOrientation est différent de UIInterfaceOrientation. les orientations gauche et droite sont inversées de sorte que lorsque le bouton d'accueil est sur la gauche, il est dans UIInterfaceOrientationLeft, mais aussi dans UIDeviceOrientationRight. – Rich

+0

Deuxièmement, si le rect est dessiné dans la vue en cours, il sera dessiné dans le système de coordonnées de cette vue. Donc, si la vue n'est pas en plein écran, elle risque de ne pas s'afficher correctement. – Rich

+0

après la rotation de l'appareil une fois qu'il apparaît là où il est attendu. voir ci-dessous pour une solution. – OscarTheGrouch

Répondre

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

Cette méthode indique le bon positionnement, que le périphérique ait été tourné ou non.

Questions connexes