来自ViewController的presentModalViewController嵌套在UIScrollview中?

时间:2012-01-27 07:58:48

标签: iphone objective-c uiviewcontroller uiscrollview

我正在创建一个iPhone应用程序,并且存在从嵌入Scrollview的viewController运行presentModalViewController的代码的问题,当我单击按钮呈现下一个视图控制器时,我得到一个慢动画和一个空白屏幕两个秒。

从我的AppDelegate我将rootViewController设置为我的ViewController(其中包含设置我的scrollview布局的代码)

我基本上在滚动视图中加载两个视图控制器,以便用户可以下拉屏幕查看历史记录。

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

{     [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信息按钮代码

  - (IBAction)btnInfo:(id)sender 
    {
        infoViewController *controller = [[infoViewController alloc] initWithNibName:@"infoViewController" bundle:nil];

        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
        [controller release];
    }

问题是当点击信息按钮我得到坏动画时,在我看来,也许按钮和presentModal View Controller应该从保存嵌套滚动视图的父ViewController运行,但我不确定如何执行此操作

任何提示或建议都会很棒。

谢谢Aaron

1 个答案:

答案 0 :(得分:-1)

首先,我不知道界面构建器是如何做到这一点的。但是以编程方式,你可能想要创建一个新的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的方式。

我希望它对你有用。

祝你好运。