tôi đã cùng một vấn đề sử dụng Cocos2d 2.0
Vấn đề của tôi là dự án đã phát triển qua nhiều năm và đã mang theo một số tác phẩm tại thoái hóa như RootViewController và UIViewController và MyRootViewController vv
Họ làm việc vào thời điểm đó nhưng rõ ràng đã nêu ra một lá cờ với ủy ban đánh giá ngày hôm nay bởi vì tôi nhận được "Tất cả các ứng dụng iPhone phải hoạt động trên iPad" thông báo từ chối. Sau khi hét to và cuối cùng chấp nhận thất bại, tôi nghĩ chính sách đó khiến cho iPhone trở nên khá khó khăn. Hãy cho tôi biết nếu tôi sai về điều này.
Mặc dù tôi đã (và vẫn còn) băn khoăn về nó, tôi nghĩ có lẽ bây giờ tôi có thể ít nhất làm sạch dự án với một giải pháp thanh lịch hơn xử lý vấn đề cơ bản: xoay thiết bị + quay nội dung. Tôi đã kết thúc bằng cách sử dụng một cái gì đó từ một dự án gần đây đã được làm việc trên và có vẻ thanh lịch hơn và thực sự làm việc: chỉ cần thêm MyNavigationController vào đầu AppDelegate của tôi.
Tôi đã thêm mã bên dưới. Tôi chắc chắn nó có thể được cải thiện. Hãy bình luận nếu bạn có thể tăng cường nó.
Kết quả là, tôi đã có thể xóa các tệp RootViewController và MyRootViewController cũ để dễ bảo trì hơn. Tôi không bao giờ hiểu mục đích của họ rất tốt. Tốt riddance!
Đây là giải pháp của tôi để hiển thị và phù hợp với định hướng thiết bị + định hướng nội dung:
trong AppDelegate.h Tôi đã phải tuyên bố những gì tôi đã làm:
// đầu của tập tin
@ giao diện MyNavigationController: UINavigationController @end
// interface inside AppDelegate.h
MyNavigationController * navController_;
// cuối tệp trước @end
@property (readonly) MyNavigationController * navController;
Đây là mã hoạt động ở đầu AppDelegate của tôi.m
@implementation MyNavigationController
// The available orientations should be defined in the Info.plist file.
// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.
// Only valid for iOS 6+. NOT VALID for iOS 4/5.
-(NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
} else if (orientation == UIDeviceOrientationLandscapeLeft) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationLandscapeRight) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
} else {
//do nothing
}
return UIInterfaceOrientationMaskLandscape;
}
//this is the one for iOS 6
- (BOOL)shouldAutorotate {
//NSLog(@"MyNavigationController - should Rotate ToInterfaceOrientation ...");
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// iPhone only
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//NSLog(@"MyNavigationController - should Rotate iPhone");
if (orientation == UIDeviceOrientationPortrait) {
//NSLog(@"should Rotate iPhone orientation is Portrait");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
if (orientation == UIDeviceOrientationPortraitUpsideDown) {
//NSLog(@"should Rotate iPhone orientation is PortraitUpsideDown");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
if (orientation == UIDeviceOrientationLandscapeLeft) {
//NSLog(@"should Rotate iPhone orientation is Landscape Left");
return UIInterfaceOrientationMaskLandscape;
}
if (orientation == UIDeviceOrientationLandscapeRight) {
//NSLog(@"should Rotate iPhone orientation is Landscape Right");
return UIInterfaceOrientationMaskLandscape;
}
return TRUE;
}
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
//NSLog(@"MyNavigationController - should Rotate iPad");
return TRUE;
}
return TRUE;
}
// Supported orientations. Customize it for your own needs
// Only valid on iOS 4/5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
// iPhone only
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
return TRUE;
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
return TRUE;
// iPad only
// iPhone only
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
return TRUE;
}
// This is needed for iOS4 and iOS5 in order to ensure
// that the 1st scene has the correct dimensions
// This is not needed on iOS6 and could be added to the application:didFinish...
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director runWithScene: [MainMenuScene scene]];
}
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// Assuming that the main window has the size of the screen
// BUG: This won't work if the EAGLView is not fullscreen
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;
//NSLog(@"MyNavigationController - Will RotateToInterfaceOrientation ...");
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rect.size = CGSizeMake(screenRect.size.height, screenRect.size.width);
}
CCDirector *director = [CCDirector sharedDirector];
CCGLView *glView = (CCGLView *)[director view];
glView.frame = rect;
}
@end
Đây là lý do tại sao tôi phải giải quyết việc này:
- tôi cần cả hai Cảnh quan và chế độ Portrait để hiển thị cảnh khác nhau.
Dưới đây là một số ảnh chụp màn hình để mô tả tình hình




bạn đã cố gắng chạy nó trên mô phỏng iPad? Bạn có @ 2x hình ảnh? – Jamie