嘿大家:)我有一个小问题,我很想听听你的经历,你会怎么处理这个问题。
我的主屏幕是一个登录屏幕,在成功登录后,我正在初始化一个新视图,并按照以下方式切换到它:SO:
// Switch views
[txtUser resignFirstResponder];
[txtPass resignFirstResponder];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[self view] cache:YES];
[UIView setAnimationDuration:0.6];
UIViewController *homeView = [[[UIViewController alloc] initWithNibName:@"HomeView" bundle:nil] autorelease];
[self.view insertSubview:homeView.view atIndex:0];
[UIView commitAnimations];
登录后我不想在设备旋转时切换视图,但是“willRotateToInterfaceOrientation”在子视图中没有捕获任何内容,只有在我将其放入父视图时才会捕获它。
所以我在考虑三个选项
我很抱歉,如果这有点混乱,希望你能理解,如果不是我喜欢详细说明并添加更多所需信息,如果需要的话:)
提前致谢, 晒。
编辑: 我添加了像@Ahmed建议的导航控制器并推送了新视图,但我得到的是一个空的灰色视图,而不是我的HomeView.xib,或许有任何想法吗?
在AppDelegate.h上
< - language:lang-cpp - >
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
在AppDelegate.m上
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window.rootViewController = self.viewController;
// Initialize navigation controller
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:self.window.rootViewController];
self.navigationController = aNavigationController;
[aNavigationController release];
[_window addSubview:[_viewController view]];
[self.window makeKeyAndVisible];
return YES;
}
然后,在成功登录后我尝试了
// Switch views
[txtUser resignFirstResponder];
[txtPass resignFirstResponder];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[self view] cache:YES];
[UIView setAnimationDuration:0.6];
UIViewController *homeView = [[[UIViewController alloc] initWithNibName:@"HomeView" bundle:nil] autorelease];
[self.navigationController pushViewController:homeView animated:YES];
[self dismissModalViewControllerAnimated:YES];
[UIView commitAnimations];
但是我得到一个空的灰色视图(就像一个新的视图)而不是我的HomeView ...任何想法怎么会发生这种情况? ...
再次感谢你们,他们是救星!
答案 0 :(得分:0)
您应该导航到另一个视图,而不是将其添加为subView。
[self.navigationController pushViewController:homeView animated:YES];
但是为此您需要在应用中使用navigationController实例。或者,如果您不使用导航模板,则应该从基于导航的模板开始。您只需在登录视图中添加homeViewController的View,这样只会添加视图,而homeViewController不会获得任何方向更改等事件。
编辑:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
YourRootViewController *rootViewController = [[YourRootViewController alloc] init];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.viewController = aNavigationController;
[aNavigationController release];
[_window addSubview:[_viewController view]];
// self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
答案 1 :(得分:0)