2012-06-18 24 views
1
[message setBackgroundColor:[UIColor redColor]]; 
[message setFrame:CGRectMake(message.frame.origin.x, message.frame.origin.y, message.frame.size.width, 20)]; 

背景顏色發生變化,因此IB中的連接正常,但UITextView的大小不變。我嘗試了多種方式,無法改變位置或大小。UITextView不會響應其框架中的更改

它工作,如果我把一個按鈕的行動,而不是從didFinishPickingMediaWithInfo回調。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 

    [picker dismissViewControllerAnimated:NO completion:^{ 

     [UIView animateWithDuration:0.1 
          delay:0.0 
         options: UIViewAnimationCurveEaseOut // Doesnt really matter since its so fast 
        animations:^{ 
         [message setFrame:CGRectMake(message.frame.origin.x, message.frame.origin.y, message.frame.size.width, 20)]; 
        } 
        completion:^(BOOL finished){[message setBackgroundColor:[UIColor redColor]]; }]; 
+0

將幀設置爲一個很大的值。可能是因爲幀變化太小而不可見。 – CodaFi

+0

你在哪裏打電話給這個?如果它在視圖加載後必須爲框架更改設置動畫。 –

+0

它在一個從按鈕調用的函數中。 –

回答

0

你用什麼方法調用這段代碼?有可能你的框架設置被隨後的更改覆蓋。幀大小尚未在viewDidLoad中設置,但它們應在調用viewWillAppear時設置,因此請在此處執行額外的佈局。

1

試試這個:

[message setBackgroundColor:[UIColor redColor]]; 

[UIView animateWithDuration:0.1 
delay:0.0 
options: UIViewAnimationCurveEaseOut // Doesnt really matter since its so fast 
animations:^{ 
    [message setFrame:CGRectMake(message.frame.origin.x, message.frame.origin.y, message.frame.size.width, 20)]; 
} 
completion:^(BOOL finished){ }]; 
+0

這讓我看到別的東西正在調整我的textview。現在我只需要弄清楚什麼。 – RyanJM

0

我最近發現,要獲得一個UITextView的內容大小(因而設置其框架「適應」的內容,無需要滾動),你需要添加文本視圖作爲子視圖第一個。在它變成子視圖之前,contentSize不會返回正確的值(並且可能設置框架不起作用)。

只是猜測...

相關問題