简体   繁体   English

如何在目标c中将具有子视图大小的子视图初始化为子视图?

[英]How to init subview into superview with the superview size , in objective c?

I try to init the subview page with the original superview. 我尝试使用原始超级视图来初始化子视图页面。

This should be a view page on the view page. 这应该是视图页面上的一个视图页面。

This method call from viewDidLoad. 从viewDidLoad调用此方法。

-(void)CreateDarkerView
{
  UIView *darker = [[UIView alloc]initWithFrame:self.verificationView.frame];
  darker.backgroundColor = [UIColor blackColor];
  darker.alpha = 0.7;
  [verificationView insertSubview:darker aboveSubview:blurBackground];


  NSLog(@"darker height = %f ",(darker.frame.size.height));
  NSLog(@"darker width = %f  \n",(darker.frame.size.width));

  NSLog(@"VerificationView height = %f ",(self.verificationView.frame.size.height));
  NSLog(@"VerificationView width = %f \n\n ",(self.verificationView.frame.size.width));



}

No matter which simulator I run (4s,5,5s,6,6+) This frame sizes remain constant. 无论我运行哪个模拟器(4s,5,5s,6,6 +),此帧大小都保持不变。

This is a Printout from console line. 这是控制台行的打印输出。

2014-09-29 15:33:32.652 roee[33353:5476056] darker height = 568.000000 
2014-09-29 15:33:32.653 roee[33353:5476056] darker width = 320.000000  

2014-09-29 15:33:32.653 roee[33353:5476056] VerificationView height = 568.000000 
2014-09-29 15:33:32.653 roee[33353:5476056] VerificationView width = 320.000000 

And for example when the simulator opens I can see that screens is not in the same size. 例如,当模拟器打开时,我可以看到屏幕尺寸不同。 The darker view is small from the Verification View. 在“验证”视图中,较暗的视图很小。

I use auto layout to the VerificationView in Xcode Version 6.0.1. 我在Xcode版本6.0.1中使用自动布局到VerificationView。

你应该叫-initWithFrame:self.verificationView.bounds代替。

You are not guaranteed to have proper geometry on viewDidLoad . 您不能保证viewDidLoad上具有正确的几何形状。 Use viewDidLayoutSubviews instad for calling -(void)createDarkerView . 使用viewDidLayoutSubviews instad调用-(void)createDarkerView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM