gpt4 book ai didi

cocoa-touch - 切换旋转 View 时,iOS 应用程序在打开时崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:06 26 4
gpt4 key购买 nike

我正在尝试在 XCode 中开发一个应用程序,该应用程序将在旋转时切换到新 View 。

这是 view1controller.h 的代码:

#import UIKit/UIKit.h

@interface TestViewController : UIViewController {}

IBOutlet UIView *portrait;
IBOutlet UIView *landscape;

@property(nonatomic,retain) UIView *portrait;
@property(nonatomic,retain) UIView *landscape;

@end

这里是 view1controller.m 的代码:

#import "view1controller.h"

@implementation TestViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
self.view = landscape;
} else if (((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))) {
self.view = portrait;
}

return YES;
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)dealloc {
[super dealloc];
}

@synthesize portrait,landscape;

@end

无论如何,应用程序打开但在打开时崩溃。

最佳答案

尝试这样的事情:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = landscapeleft;
}

if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}

if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = portraitupsidedown;
}

if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = landscapeleft;
}


return YES;
}

关于cocoa-touch - 切换旋转 View 时,iOS 应用程序在打开时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4764956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com