我有ViewController
與UITextField
(俯視圖)和UITextView
(仰視圖)。我想在用戶開始編輯時將UITextView
移動到視圖的頂部。 當用戶從UITextView
開始編輯時,一切都很好,但是當用戶首先要編輯UITextField
,然後UITextView
(沒有隱藏鍵盤)時,它不起作用。 UITextField
已隱藏,但UITextView
不會更改其框架。 我試圖使用UIKeyboardDidShowNotification
,但只有在彈出鍵盤時才調用它。更改UITextView框架
碼來重現問題: ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *titleTF;
@property (weak, nonatomic) IBOutlet UITextView *bodyTV;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(void)textViewDidBeginEditing:(UITextView *)textView {
self.titleTF.hidden=YES;
CGRect newFrame=CGRectMake(20, 20, textView.frame.size.width, 100);
textView.frame=newFrame;
}
@end
運行的應用程序,然後點擊UITextView的,應用程序將是這樣的: http://imageshack.us/photo/my-images/694/32568213.png 現在一切都很好(UITextField被隱藏,UITextView被移動並調整大小)。
再次啓動應用程序。首先點擊UITextField,然後點擊UITextView。應用看起來像這樣: http://imageshack.us/photo/my-images/843/66433184.png UITextField是隱藏的,但UITextView沒有改變他的框架。
請問這個方法火,當你開始編輯?你試過NSLog嗎? – 2013-05-05 12:01:42
是的,它的工作。它總是隱藏titleTF。 – 2013-05-05 12:03:16
你在這個視圖控制器中只有一個textView嗎? – 2013-05-05 12:19:19