Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27187

incorrect view size ios

I am using UIViewController for display my view. My view have been created in interface builder.

Right now these are next parameters for view:

width: 568 height: 320 Orientation: Landscape

in ViewController I have next code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

in info.plist I have added just two interface orientation right and left.

but when I try to output width of my view in code I get 320 and when I try to output height it write down in console 568 but I expect 320 instead.

I don't know why it works like this. Any suggestions?

even if I add this:

[self.view setFrame:CGRectMake(0, 0, 568, 320)]; in viewDidLoad method. even then I have inccorect height

I need to know width size I use in this method:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat width = 0.0f;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        width = 568.0f;
    } else {
        width = 1024.0f;
    }    
    NSInteger page = scrollView.contentOffset.x / width;
    NSLog(@"%d", page);
}

Right now I use hardcode variable of width, but how come. Why I can't use self.view.frame.size.width because the sides swop each other - because.

Upvotes: 1

Views: 1036

Answers (2)

Hemang
Hemang

Reputation: 27072

Please add LaunchScreen.storyboard in your project and set it as your Launch Screen under

Targets > General > App Icons and Launch Images > Launch Screen file.

Upvotes: 0

txulu
txulu

Reputation: 1802

Maybe you're printing width and height in the viewDidLoad method before the orientation occurs. Try to print it on viewWillAppear or with performSelector:afterDelay:

Another thing that might affect the dimension of the view is how you set the autoresizing mask on the interface builder (the red arrows below the x,y,height,width section on the right panel)

Upvotes: 2

Related Questions