我有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