从嵌套在 UIScrollview 中的 ViewController 呈现ModalViewController?

发布于 2024-12-29 09:54:01 字数 2475 浏览 1 评论 0原文

我正在创建一个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];

}

ma​​inCalculatorViewController 信息按钮代码

  - (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-01-05 09:54:01

首先,我不知道界面生成器是如何做到这一点的。但以编程方式,您可能应该创建一个新的 navigationController 来处理 modalVC。

-(void)showModalVC
{
    self.myModalVC = [[ModalVC alloc] init];

    self.myModalVC.dismissDelegate = self;

    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:self.myModalVC];

    navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad

    UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
    navTopItemTitle.text = @"Modal shizzle";
    navTopItemTitle.backgroundColor = [UIColor clearColor];
    navTopItemTitle.textColor = [UIColor whiteColor];
    navTopItemTitle.textAlignment = UITextAlignmentCenter;

    [navController.navigationBar.topItem setTitleView:navTopItemTitle];

    [self presentModalViewController:navController animated:YES];

    [self.addTabViewController release];
    [navController release];
}

这就是我使用 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.

-(void)showModalVC
{
    self.myModalVC = [[ModalVC alloc] init];

    self.myModalVC.dismissDelegate = self;

    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:self.myModalVC];

    navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad

    UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
    navTopItemTitle.text = @"Modal shizzle";
    navTopItemTitle.backgroundColor = [UIColor clearColor];
    navTopItemTitle.textColor = [UIColor whiteColor];
    navTopItemTitle.textAlignment = UITextAlignmentCenter;

    [navController.navigationBar.topItem setTitleView:navTopItemTitle];

    [self presentModalViewController:navController animated:YES];

    [self.addTabViewController release];
    [navController release];
}

This is how I work with ModalVC's.

I hope it's usefull to you.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文