从嵌套在 UIScrollview 中的 ViewController 呈现ModalViewController?
我正在创建一个iPhone应用程序,并且在从嵌套在Scrollview中的viewController运行presentModalViewController代码时遇到问题,当我单击按钮来呈现下一个视图控制器时,我会看到一个缓慢的动画和两秒钟的空白屏幕。
从我的 AppDelegate 中,我将 rootViewController 设置为 ViewController (其中包含设置滚动视图布局的代码),
我基本上在滚动视图内加载两个视图控制器,以便用户可以下拉屏幕以查看历史记录。
AppDelegateCode
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *controller = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = controller; //self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
ViewController 代码
- (void)viewWillAppear:(BOOL)animated
{ [超级viewWillAppear:动画];
CGRect bounds = self.view.bounds;
vScroller.bounces = NO;
vScroller.pagingEnabled = YES;
vScroller.showsVerticalScrollIndicator = FALSE;
vScroller.alwaysBounceVertical = FALSE;
vScroller.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2);
// History View Controller..
historyViewController *historyView = [[historyViewController alloc] initWithNibName:@"historyViewController" bundle:nil];
[vScroller addSubview:historyView.view];
[historyView release];
// Reconfigure Content Offset
vScroller.contentOffset = CGPointMake(0, bounds.size.height);
// Calculator View Controller
mainCalculatorViewController *mainView = [[mainCalculatorViewController alloc] initWithNibName:@"mainCalculatorViewController" bundle:nil];
mainView.view.frame = CGRectOffset(bounds, 0, bounds.size.height);
[vScroller addSubview:mainView.view];
}
mainCalculatorViewController 信息按钮代码
- (IBAction)btnInfo:(id)sender
{
infoViewController *controller = [[infoViewController alloc] initWithNibName:@"infoViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
问题是,当单击信息按钮时,我得到的动画很糟糕,在我看来,按钮和presentModal 视图控制器可能应该从保存嵌套滚动视图的父ViewController 运行但我不确定如何做到这一点。
任何提示或建议都会很棒。
谢谢亚伦
I am creating an iPhone app and have an issue with running code for presentModalViewController from a viewController which is nested in a Scrollview, when I click the button to present the next view controller I get a slow animation and a blank screen for two seconds.
From my AppDelegate I am setting the rootViewController to my ViewController (which contains the code to set my scrollview layout)
I'm basically loading two view controllers inside a scrollview so that the user can pull down the screen to see the history.
AppDelegateCode
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ViewController *controller = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = controller; //self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
ViewController Code
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect bounds = self.view.bounds;
vScroller.bounces = NO;
vScroller.pagingEnabled = YES;
vScroller.showsVerticalScrollIndicator = FALSE;
vScroller.alwaysBounceVertical = FALSE;
vScroller.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2);
// History View Controller..
historyViewController *historyView = [[historyViewController alloc] initWithNibName:@"historyViewController" bundle:nil];
[vScroller addSubview:historyView.view];
[historyView release];
// Reconfigure Content Offset
vScroller.contentOffset = CGPointMake(0, bounds.size.height);
// Calculator View Controller
mainCalculatorViewController *mainView = [[mainCalculatorViewController alloc] initWithNibName:@"mainCalculatorViewController" bundle:nil];
mainView.view.frame = CGRectOffset(bounds, 0, bounds.size.height);
[vScroller addSubview:mainView.view];
}
mainCalculatorViewController info Button Code
- (IBAction)btnInfo:(id)sender
{
infoViewController *controller = [[infoViewController alloc] initWithNibName:@"infoViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
The problem is when clicking the info button I get the bad animation, it seems to me that perhaps the button and presentModal View Controller should be ran from the parent ViewController which holds the nested scrollviews but I am unsure of how to do this.
Any tips or suggestions would be great.
Thanks Aaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我不知道界面生成器是如何做到这一点的。但以编程方式,您可能应该创建一个新的 navigationController 来处理 modalVC。
这就是我使用 ModalVC 的方式。
我希望它对你有用。
祝你好运。
First of all i don't know how interface builder does this. But programmatically you should probably want to make a new navigationController to handle the modalVC.
This is how I work with ModalVC's.
I hope it's usefull to you.
Good luck.