Domanda

Questo può sembrare una domanda newbie, però io sono nuovo a iOS dev,

Ho UIWebView e UITableView sul mio punto di vista iPad. In shouldAutorotateToInterfaceOrientation li a ridimensionare per bel look come questo.

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {    
        if( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2);
            self.mTextView.frame = f;
            f = CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2);
            self.mTableView.frame = f;
        }
        if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {     
            CGRect f = CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
            self.mTextView.frame = f;
            f = CGRectMake(self.view.frame.size.width / 2, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
            self.mTableView.frame = f;        
        }   
        return YES;
    }

Ora la domanda: Per il primo carico visualizzazione tabella viene disegnata con dimensioni corrette ma quando passo modalità verticale poi ritorna alla modalità orizzontale l'UITableView diventa più larga specificato dal telaio. Allora, perché questo accade e come risolvere questo problema?

PS. Ho provato anche per impostare i frame per tutte le celle con lo stesso metodo non ha aiutato.

PSS. Ciò accade solo su dispositivo, sul simulatore UITableView viene visualizzato correttamente

È stato utile?

Soluzione

shouldAutorotateToInterfaceOrientation: restituisce solo un valore booleano che indica se il controller della vista supporta l'orientamento specificato, non si deve fare alcuna trasformazione interfaccia utente in questo metodo, anziché fare tutto willAnimateRotationToInterfaceOrientation:duration:.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{    
    if( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2);
        self.mTextView.frame = f;
        f = CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2);
        self.mTableView.frame = f;
    }
    if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {     
        CGRect f = CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
        self.mTextView.frame = f;
        f = CGRectMake(self.view.frame.size.width / 2, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
        self.mTableView.frame = f;        
    }
}

Date un'occhiata alla documentazione per UIViewController , è ben spiegato.

Altri suggerimenti

iOS chiama questa funzione solo una volta! Per fare questo lavoro bello come ci si aspetta, è necessario aggiungere questa riga nella funzione (void)viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

E la funzione (void)orientationChanged:(id)object fare:

- (void)orientationChanged:(id)object{
    UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication] statusBarOrientation;

    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
        // some works
    }else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){
        // another works
    }
}

Spero che sia utile per voi!

È possibile modificare le dimensioni del UITableView sia in modalità verticale e orizzontale. UITableView cambio formato automaticamente in un rapporto rispetto alla modalità di orientamento precedente. Modo da poter risolvere dimensione desiderata per entrambe le modalità.

Spero che questo lavoro per voi.

Si prega di verificare la proprietà autoResizing dei punti di vista.

Il modo più semplice è che si può fare 2 vista differente per la modalità verticale e orizzontale in modo ogni volta che cambia la modalità si può facilmente modificare la visualizzazione. In questo modo:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        self.view = self.portraitView;
    else 
        self.view = self.landscapeView;
    [tblScore reloadData];
    return YES;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top