简体   繁体   中英

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.

-(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.

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.

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

You are not guaranteed to have proper geometry on viewDidLoad . Use viewDidLayoutSubviews instad for calling -(void)createDarkerView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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