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
525 views
in Technique[技术] by (71.8m points)

ios6 - Set keyboard orientation only (iOS 6)

my app has been working fine until I've tried making some changes using the ios 6 SDK

The app runs in portrait mode 99% of the time. This has been constrained by only allowing portait mode to be available in the info.plist

There is one view controller which needs to be shown in landscape mode. This is achieved "manually" by simply rotating the view by 90 degrees, like so:

self.view.transform = CGAffineTransformMakeRotation(3.14159/2);

This still works fine in iOS 6.

However, this view controller has some text fields. When the user taps one it shows the keyboard. Since I've only rotated the view (and not actually changed the orientation of the device), the keyboard comes out in portrait mode, which is no good.

In previous versions of iOS, I set the orientation of the status bar to be landscape, and as a byproduct, this would set the keyboard to be landscape as well, like this:

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

However, this has stopped working for iOS 6.

I have read a million stack overflows trying to get this to work, but still have no luck.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Changing the keyboard orientation and transform is an difficult part and not a good solution(especially when it changes status bar orientations).

Better solutions is to allow application to support all orientations.

enter image description here

Implement the Orientation delegates inside your ViewControllers asper the rotation support.

For Supporting only Landscape

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

- (BOOL)shouldAutorotate
{
    return NO;
}

For Supporting only Portrait

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

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

...