大佬教程收集整理的这篇文章主要介绍了xcode / iOS:自动调整以填充视图 – 显式帧大小是必不可少的?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
似乎我无法通过使用autoresizingMask和autoresizesSubviews的API指定属性来使UITextView完成此操作.如此处所示设置这些没有任何作用;即使superView填充屏幕,UITextView仍然很小.
// use exisTing instantiated view inside view controller; // ensure autosizing enabled self.view.autoresizesSubviews = YES; self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth; // create textview textView = [[[UITextView alloc] autorelease] initWithFrame:CGRectMake(0,1,1)]; // enable textview autoresizing [textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight]; // add textview to view [self.view addSubview:textView];
但是,如果我在视图控制器中实例化我自己的视图,替换它的’.view’属性,那么一切都按预期工作,并且textView填充其超级视图:
// reinstantiate view inside view controller self.view = [[UIView alloc]init]; // create textview textView = [[[UITextView alloc] autorelease] initWithFrame:CGRectMake(0,1)]; // enable textview autoresizing [textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight]; // add textview to view [self.view addSubview:textView];
我在所有这些初始化程序/方法中尝试了两个代码块,并且在每种情况下都会出现相同的情况:
-(id)init; -(id)initWithFrame:(CGRect)frame; -(void)viewDidLoad;
我意识到重新实现UIViewController的’.view’是非常难看的,任何人都可以解释我做错了吗?我假设我可以通过在我的UIViewController中使用初始帧设置代码来重新调整UITextView的大小来解决这个问题,然后自动调整将按需运行.
-(void)viewDidLoad { textView.frame = self.view.frame; }
…但是貌似view.frame没有在这个阶段设置,它没有定义’.size’值,所以textView仍然很小.
实现我想要的正确方法是什么?我必须通过UITextView:initWithFrame明确指定全屏尺寸,以使其填充其超视图吗?
对于您提供的任何建议,我将不胜感激.
这就是你所需要的:
textView = [[[UITextView alloc] autorelease] initWithFrame:self.view.bounds]; [textView setAutoresizingMask:UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight];
以上是大佬教程为你收集整理的xcode / iOS:自动调整以填充视图 – 显式帧大小是必不可少的?全部内容,希望文章能够帮你解决xcode / iOS:自动调整以填充视图 – 显式帧大小是必不可少的?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。