在 iPad iOS 4.3 中支持纵向和横向界面方向的最佳实践

发布于 2024-12-29 05:10:52 字数 656 浏览 3 评论 0原文

在文档中,

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW6

他们有使用 performSegueWithIdentifier:sender:dismissViewControllerAnimated:completion: 在 iOS 5.0 及更高版本中可用。

有没有什么聪明的方法可以在 iOS 4.3 中针对不同的 ipad 界面方向使用多个笔尖。

In the document,

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW6

they have used performSegueWithIdentifier:sender: and dismissViewControllerAnimated:completion: which are available in iOS 5.0 and later.

Is there any smart way to use multiple nibs for different ipad interface orientations in iOS 4.3.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那伤。 2025-01-05 05:10:52

假设您有一个 PortraitViewController 和一个 LandscapeViewController。

您将需要以下内容:

@interface PortraitViewController : UIViewController {
    BOOL isShowingLandscapeView;
    LandscapeViewController *landscapeViewController;
}

@implementation PortraitViewController

- (void)viewDidLoad 
{
    [super viewDidLoad];

    landscapeMainViewController = [[LandscapeMainViewController alloc] initWithNibName:@"LandscapeMainViewController" bundle:nil];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIDevice currentDevice]  endGeneratingDeviceOrientationNotifications];
    [landscapeMainViewController release]; landscapeMainViewController = nil;
    [super dealloc];
}

- (void)orientationChanged:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {
        [self presentModalViewController:landscapeMainViewController animated:YES];
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}

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

@end


@interface LandscapeViewController : UIViewController
@end

@implementation LandscapeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil  bundle:nibBundleOrNil])
    {
        self.wantsFullScreenLayout = YES;
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    }
    return self;
}

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

@end

学分:http://www. edumobile.org/iphone/iphone-programming-tutorials/alternativeviews-in-iphone/

Let's say that you have a PortraitViewController and a LandscapeViewController.

You will need the following:

@interface PortraitViewController : UIViewController {
    BOOL isShowingLandscapeView;
    LandscapeViewController *landscapeViewController;
}

@implementation PortraitViewController

- (void)viewDidLoad 
{
    [super viewDidLoad];

    landscapeMainViewController = [[LandscapeMainViewController alloc] initWithNibName:@"LandscapeMainViewController" bundle:nil];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIDevice currentDevice]  endGeneratingDeviceOrientationNotifications];
    [landscapeMainViewController release]; landscapeMainViewController = nil;
    [super dealloc];
}

- (void)orientationChanged:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {
        [self presentModalViewController:landscapeMainViewController animated:YES];
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}

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

@end


@interface LandscapeViewController : UIViewController
@end

@implementation LandscapeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil  bundle:nibBundleOrNil])
    {
        self.wantsFullScreenLayout = YES;
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    }
    return self;
}

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

@end

Credits: http://www.edumobile.org/iphone/iphone-programming-tutorials/alternativeviews-in-iphone/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文