ios - Objective-C - When I add a subview, my subview is going out of the screen at the bottom. Misunderstanding of frames? -
To practice purpose-C, and I try to do everything in the program.
I have a simple view that I add to my view of ViewController, but this subview is going out of the screen. When I set my frame, the status of X and Y is respected, but the rest do not ...
 Here is a screenshot of my result:  
 
As you can see ... the red subway is going out of the screen.
 This is my  loadView  where I add that subview: 
Home ViUi Controller M - loadview
  - (zero) loadview {self.view = [[UIView alloc] initWithFrame: [UIScreen main screen]. Bounce]; UIView * SubView = [[UIView alloc] initWithFrame: CGRactMake (15, 15, self v. U.fr. frame. Fourth-30, self.view.frame.size.height - 30)]; [Subview setbackgram color: [UIColor redColor]]; [Self.view addSubview: subview]; }    For padding, I put 15 for the status   In my   I do not understand this strange behavior for height ... if anyone has a good explanation for this, please, please.   Thank you  x  and  y  ... and for the frame, I did Remove the padding and calculate with the size of  self.view  ... As you see, it works well for  width , but  height   AppDelegate.h , I have set the  navigation controller. Navigationbar.translucent = NO; , for that time I set the position for  x  and  y , it starts well after the  navigation bar  is. 
 First, you should not rely on the value of the code <  viewDidoad  in self.view . It is set to a right value later, in  viewWillAppear: . You can keep your code, if you change the size of your code automatically, when  self.view  is displayed. For that, set the  autoresizingMask  subview: 
  subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;   (If you use automatic layout, add the set of barriers.)
 Also, instead of  bound   frame : 
  UIView * subview = [[UIView alloc] initWithFrame: CGRKMakec (15, 15, self view.bound.ize.width - 30, self. View .bounds.size.height - 30)];    It does not make any difference here, but it often happens, e.g. If you calculate the frames on the basis of the  x  and  y  the original frames. 
Comments
Post a Comment