UIView background sizing issue

后端 未结 7 729
梦如初夏
梦如初夏 2021-01-28 07:06

I\'m adding a UIImageView to the UIViewController\'s UIView as I would normally, with the frame of the image view being the same as self.view to make sure that the

相关标签:
7条回答
  • 2021-01-28 07:17

    Try UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; isntead. Using bounds instead of frame

    0 讨论(0)
  • 2021-01-28 07:21

    I had the same problem and it solved with this:

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    

    self.view.frame give you the wrong x and y when status bar is not hidden

    0 讨论(0)
  • 2021-01-28 07:24

    Try to change self.view.frame to self.view.bounce when you add imageView into self.view.

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    

    Or just use CGRectMake(0,0,320,568)

    0 讨论(0)
  • 2021-01-28 07:25

    on the viewDidLoad method your UIViewController's xib is loaded and your updated values regarding your User Interface is not detected.

    This causes no trouble if your UIView is exactly same (no UINavigationBar, UITabbar, status bar or device -iPhone 3.5 inch / 4 inch change). But if you are changing anything in the process, you might get false values on viewDidLoad.

    Easiest way to check this is to debug your screen and view bounds on the viewDidAppear, after UI gets updated.

    Please check your xib/storyboard. There is a change between your current UI and designed interface.

    To solve this you might use a function updateUI on the viewDidAppear and update related view's again.

    [self.imageView setFrame:self.view.frame]
    

    this will fix it.

    0 讨论(0)
  • 2021-01-28 07:27

    Try move [self.navigationController setNavigationBarHidden:YES]; to

    - (void) viewWillAppear: (BOOL) animated
    {
        [super viewWillAppear: animated];    
    
        [self.navigationController setNavigationBarHidden: YES
                                                 animated: NO];
    }
    
    0 讨论(0)
  • 2021-01-28 07:30

    In your app delegate set the FullScreenLayout to YES just before you make it the view controller the root view controller:

    ViewController *vc = [[ViewController alloc] init];
    [vc setWantsFullScreenLayout:YES];
    [[self window] setRootViewController:vc];
    

    or you can set it in viewDidLoad

    [self setWantsFullScreenLayout:YES];
    

    A summary on setWantsFullScreenLayout: When a view controller presents its view, it normally shrinks that view so that its frame does not overlap the device’s status bar. Setting this property to YES causes the view controller to size its view so that it fills the entire screen, including the area under the status bar. (Of course, for this to happen, the window hosting the view controller must itself be sized to fill the entire screen, including the area underneath the status bar.) You would typically set this property to YES in cases where you have a translucent status bar and want your view’s content to be visible behind that view. From here

    Hope this helps.

    0 讨论(0)
提交回复
热议问题