1

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.

4

2 に答える 2

2

向きが発生する前に、viewDidLoadメソッドで幅と高さを印刷している可能性があります。viewWillAppearまたはperformSelector:afterDelay:で印刷してみてください

ビューの寸法に影響を与える可能性のあるもう1つのことは、Interface Builderで自動サイズ変更マスクを設定する方法です(右側のパネルのx、y、height、widthセクションの下にある赤い矢印)

于 2012-11-01T20:18:58.750 に答える
0

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.

于 2017-06-01T09:38:47.400 に答える