2014-02-21 28 views
-3

我有一個UITextView縱向大小500px寬度。
我通過代碼添加它作爲子視圖,但我不能在viewdidapper獲得正確的大小,如果應用程序在橫向模式下打開。
設備旋轉後,它正常工作。如果打開景觀沒有。 如何在打開景觀時計算此textview的正確尺寸?獲取正確UIView大小時打開橫向

謝謝

+0

你能發佈代碼在哪裏創建文本視圖嗎? – Antonio

回答

-1

添加通知在viewWillAppear中功能

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

的方向變化通知該功能

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

,你計算你的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 
}} 

我希望這可以幫到

相關問題