首页 > 移动平台 > 详细

IOS之导航栏中添加UITextView控件bug

时间:2015-01-21 09:02:27      阅读:1586      评论:0      收藏:0      [点我收藏+]

今天遇到一个奇怪的问题,如下:

在导航栏控制器的rootviewcontroller中,添加了一个UITextView控件,代码如下:

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title =@"Test";

    UITextView *textview = [[UITextViewalloc]init];

    textview.frame = CGRectMake(10, 100, 300, 200);

    textview.backgroundColor = [UIColorgreenColor];

    textview.layer.cornerRadius =5;

    textview.layer.masksToBounds =YES;

    textview.font=[UIFontboldSystemFontOfSize:14];

    [self.viewaddSubview:textview];

}


运行效果如下:

技术分享

那么问题出现了,光标出现在中间了,很明显,导航栏的高度和光标距离UITextView顶部的距离是相同的

把代码做如下修改,便解决问题:

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title =@"Test";

    //在添加UITextView之前,添加个UIView

    [self.viewaddSubview:[UIViewnew]];

    

    UITextView *textview = [[UITextViewalloc]init];

    textview.frame = CGRectMake(10, 100, 300, 200);

    textview.backgroundColor = [UIColorgreenColor];

    textview.layer.cornerRadius =5;

    textview.layer.masksToBounds =YES;

    textview.font=[UIFontboldSystemFontOfSize:14];

    [self.viewaddSubview:textview];

}


运行效果如下:

技术分享

由此可见:在导航栏的ViewController中添加UITextView控件前,需要先添加一个UIView,否则,光标会下移一个(导航栏+状态栏)的高度。

具体原因不知为何会这样,请大家指教。


IOS之导航栏中添加UITextView控件bug

原文:http://blog.csdn.net/lcn001/article/details/42933445

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!