Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

iphone - Reporting incorrect bounds in landscape Mode

I am having an issue with Landscape mode in my iPad application.

I created a very small new project to show my issue I set UIInterfaceOrientation in the pList to UIInterfaceOrientationLandscapeRight

In app delegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window makeKeyAndVisible];
    MyController *myController = [[MyController alloc] init];
    [self.window addSubview:myController.view];

    return YES;
}

In MyController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"Bounds Height:%f %f", self.view.bounds.size.height, self.view.bounds.size.width);
}

I have also tried putting this in viewDidLoad with same results

If I start the application while holding the device in landscape orientation the NSLog outputs

Bounds Height: 1004.000000 Bounds Width: 768.000000

What do I need to do to get the correct results? I am new to this iOS programming, all I am trying to do is anchor a UISlider to the bottom of the screen but when I am getting the incorrect coordinates I am unsure how to do it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I dont think the original question was answered here because Im experiencing the same issue.

The key here is that if the simulator / device is in Landscape mode, and Then you start your program, self.view.(frame or bounds) retrieves the Portrait height and width. If your program is already running and then you rotate it gives the correct value. This only occurs when the device is started in Landscape and is not rotated.

Has anyone else found a solution to this or knows what Im doing wrong? Please & Thank you.

Possible Solution

I had previously been calling my method from the viewDidLoad method. It turns out that the view was still transitioning. I had better luck by calling my function from viewDidAppear that is called after everything is done.

Hope that helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...