我是一个相当新的iOS开发。我的应用有多个viewController
,例如 -
这些屏幕中的每一个都有自己的viewController
。
使用动画在任意两个任意viewController
之间进行转换的最佳方式是什么?
我目前的做法是 -
viewController
AppDelegate.m
的引用
这既麻烦又效率很低,而且我不太清楚如何在这里整合动画过渡。
我看到UINavigationController
的一些例子,但它看起来像是一个"堆栈"你可以进入然后退出的观点。我不想在这里保留历史记录,只需从任何视图切换到另一个视图。
有什么好方法可以实现这个目标吗?
谢谢!
答案 0 :(得分:2)
试试此代码。
AppDelegate.h
#import <UIKit/UIKit.h>
#import "LoginViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) UINavigationController *navigationController;
@property (strong,nonatomic) LoginViewController *loginVC;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "LoginViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.loginVC = [[LoginViewController alloc]initWithNibName:nil bundle:nil];
self.loginVC.title = @"Login Page";
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.loginVC];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
}
LoginViewController.h
#import <UIKit/UIKit.h>
#import "MyProfileViewController.h"
@interface LoginViewController : UIViewController
@property (strong,nonatomic)MyProfileViewController *myProfileVC;
@end
LoginViewController.m文件中的登录按钮操作
- (IBAction)pushMyProfileView:(id)sender
{
self.myProfileVC = [[MyProfileViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:self.myProfileVC animated:YES];
}
答案 1 :(得分:0)
基本上你可以通过使用:
来实现这一点包含API可能就是您正在寻找的,您创建了一个负责管理其子视图控制器的表示的UIViewController。这是Apple Documentation,里面有很多例子。
答案 2 :(得分:0)
作为初学者,我相信最简单的解决方案是使用Storyboard
并在视图控制器之间创建一个segue。
在ViewController中,您应该覆盖prepareForSegue:
方法以将数据传递到segue.destinationViewController