Pergunta

I have a UITextView that in portrait sizes 500px width.
I add it by code as subview but i can't be able in viewdidapper to get the correct size if the app is opened in landscape mode.
After the device rotation it works right. If opened landscape no. How can i calculate the correct dimension of this textview when opening landscape?

Thank you

Nenhuma solução correta

Outras dicas

Add a notifier in the viewWillAppear function

    -(void)viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];
}

The orientation change notifies this function

- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}

and you calculate the size of your textView

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    //calculate the portrait textView size   
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{
    //calculate the landscape textView size  
}}

i hope this help

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top