【问题标题】:Display navigationController on top在顶部显示 navigationController
【发布时间】:2012-11-26 11:25:22
【问题描述】:

我在我的应用程序中设置了一个子视图“弹出窗口”,如果用户点击子视图弹出窗口上的按钮,我想显示一个 navController。到目前为止,我已经设置了按钮,但是如果我点击按钮,navigationController 会出现在我的弹出窗口下!?我已经搜索了一些解决方案,但我没有找到任何解决方案。整个控制器实际上显示在一个文件夹中,您可以在这里找到:https://github.com/jwilling/JWFolders 所以 viewDidLoad 属于文件夹和根视图。 我试图将其作为弹出窗口的子视图,但这也不起作用。有谁知道如何治疗?我也以编程方式设置了弹出窗口和导航控制器。 提前致谢。

我的代码:

导航控制器设置:

    - (IBAction)dothis:(id)sender {

    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

    // Set browser options.
    browser.wantsFullScreenLayout = YES;
    browser.displayActionButton = YES;


    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];

    [self presentModalViewController:navController animated:YES];

    NSMutableArray *photos = [[NSMutableArray alloc] init];
    MWPhoto *photo;
    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"star" ofType:@"png"]];
    photo.caption = @"The star is soo beateful...";
    [photos addObject:photo];

    self.photos = photos;

}


- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

弹出代码:

   -(IBAction)mehr:(id)sender {
    //the popup size and content
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 440)];
    CGRect welcomeLabelRect = contentView.bounds;
    welcomeLabelRect.origin.y = 20;
    welcomeLabelRect.size.height = 40;
    UILabel *welcomeLabel = [[UILabel alloc] initWithFrame:welcomeLabelRect];

//an simple activityindicator

 activityindi = [[UIActivityIndicatorView  alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityindi.frame = CGRectMake(120, 200, 40, 40);
    [activityindi startAnimating];
    [contentView addSubview:activityindi];

   //The Imageview
    CGRect infoimagerect = CGRectMake(5, 70, 270, 200);

    UIImageView *infoimage = [[UIImageView alloc] initWithFrame:infoimagerect];

        //and the Button

cubut = [UIButton buttonWithType:UIButtonTypeCustom];
    [cubut addTarget:self
              action:@selector(dothis:)
    forControlEvents:UIControlEventTouchUpInside];
    [cubut setTitle:nil forState:UIControlStateNormal];
    cubut.frame = CGRectMake(5, 70, 270, 200);

//retrieving data from parse.com
PFQuery *query = [PFQuery queryWithClassName:@"My-Application"];
    [query getObjectInBackgroundWithId:@"My-ID"
                                 block:^(PFObject *textdu, NSError *error) {
                                     if (!error) {

//hide the Button if there is no image
                                         cubut.hidden=YES;

                                         //the headline of popup
                                         UIFont *welcomeLabelFont = [UIFont fontWithName:@"copperplate" size:20];

                                         welcomeLabel.text = [textdu objectForKey:@"header"];
                                         welcomeLabel.font = welcomeLabelFont;
                                         welcomeLabel.textColor = [UIColor whiteColor];
                                         welcomeLabel.textAlignment = NSTextAlignmentCenter;
                                         welcomeLabel.backgroundColor = [UIColor clearColor];
                                         welcomeLabel.shadowColor = [UIColor blackColor];
                                         welcomeLabel.shadowOffset = CGSizeMake(0, 1);
                                         welcomeLabel.lineBreakMode = UILineBreakModeWordWrap;
                                         welcomeLabel.numberOfLines = 2;
                                         [contentView addSubview:welcomeLabel];

//the image from parse

 if (!error) {
                                             PFFile *imageFile = [textdu objectForKey:@"image"];
                                             [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                                                 if (!error) {
                                                     UIImage *image = [UIImage imageWithData:data];
                                                     infoimage.image = image;
                                                     infoimage.contentMode = UIViewContentModeScaleAspectFit;
                                                     //show the button when the image appears
                                                     cubut.hidden = NO;




                                                     [contentView addSubview:infoimage];
                                                    //stop the activityindicator
                                                     [activityindi stopAnimating];

                                                 }
                                             }];
                                         }
 } else {
                                        //show some text 
                                         welcomeLabel.text = @"No connection!";
                                         [welcomeLabel sizeToFit];
//hide the button
                                         cubut.hidden = YES;

                                         [contentView addSubview:infoLabel];
//stop the activityindicator
                                         [activityindi stopAnimating];
                                     }

                                 }];
//add the content to the KNGModal view



 [[KGModal sharedInstance] showWithContentView:contentView andAnimated:YES];
}

我的 viewDidLoad

- (void)viewDidLoad
{

but.hidden = YES;
PFQuery *query = [PFQuery queryWithClassName:@"myapp"];
    [query getObjectInBackgroundWithId:@"Rgq5vankdf"
                                 block:^(PFObject *textu, NSError *error) {
                                     if (!error) {
but.hidden = NO;
                                         but.color = [UIColor colorWithRed:0.90f green:0.90f blue:0.90f alpha:1.00f];

} else {

                                         //if failure
                                        but.hidden = YES;
                                        mol.text = @"No Connection";

                                     }

                                 }];


    [super viewDidLoad];

}

图片:

打开文件夹的按钮:

文件夹本身:

弹出窗口:

提前致谢。

【问题讨论】:

  • 你能告诉我添加这个弹出窗口的代码吗..我无法从这里找到..如果它存在突出显示它..
  • 弹出框是 KNGModal 所以代码行:[[KGModal sharedInstance] showWithContentView: contentView andAnimated: YES];
  • 或查看整个项目:github.com/kgn/KGModal
  • ok.. 我看到了 KGModal 代码库.. 它是一个弹出窗口,就像一个 alertView,所以当它出现时,它下面的视图将被禁用,一旦它被关闭,视图就会被交互。 . 那么你是如何在你的应用程序中使用的.. 你想要交互弹出和在它下面查看吗..
  • 我希望照片浏览器出现在上方...实际上在弹出窗口的顶部,如果浏览器已关闭,弹出窗口仍然存在...谢谢

标签: iphone ios uinavigationcontroller subview


【解决方案1】:

从到目前为止的讨论和调试代码中,您希望在带有导航控制器的弹出窗口中拥有照片浏览器。

所以这里是实现这个功能的sample code,看看吧。

我使用了相同的KGModal 示例代码并根据要求进行了扩展。我使用 Xib 来查看带有导航栏的视图。

要从应用程序中的任何位置关闭弹出窗口,您可以使用以下行,因为它是共享实例。

[[KGModal sharedInstance] hideAnimated:YES];

更新:

在 folderView 中显示照片浏览器的原因是,您试图在 folderView 中显示 photoBrowser,因此它在高度非常小的 folderView 中显示并且看不到任何照片。

所以我的建议是,当用户点击弹出窗口以查看 photoBrowser 时,您只需从 viewController 类中删除弹出窗口并呈现 photoBrowser,因为除了这个类之外,所有内容都通过视图处理。

我已经按照上面的方法修改好了,你给的代码,下载代码here看看。

如果它满足您的需求,请告诉我。

谢谢

【讨论】:

  • 是的,它可以工作,但视图控制器仅显示在 kgmodal 中,并且 kgmodal 不适合屏幕尺寸。在 Iphone 4/4s 上,我在导航栏中看不到整个关闭按钮,而在 Iphone 5 上,整个视图的底部和顶部有一些未填充的地方。
  • 不能在 kngmodal 中显示控制器并正常设置吗?通常,它像其他所有控制器一样从按钮出现?我认为 kng 模态会导致这个问题。那就是我想要一个普通的控制器显示在所有视图之上,并且在关闭后弹出窗口仍然存在
  • 我仍然没有得到你,一旦你立即关闭控制器,你可以从上面的代码中删除弹出窗口对..?
  • 等待...我点击文件夹视图控制器中的一个按钮,使 kng 模态显示带有图像和一些文本。我设置了一个按钮,该按钮位于具有相同 CGRect 的按钮上,如果我点击此按钮,它应该会出现一个新的 MBhotoviewcontroller。它出现在文件夹视图控制器中。所以我什至看不到控制器。
  • 不.. 仍然不知道你是如何实现的.. 创建一个示例代码,有类似的问题并发给我..
【解决方案2】:

我注意到这行代码:

[[KGModal sharedInstance] showWithContentView: contentView andAnimated: YES];

我只能认为,因为它是一个单例,所以它在 UIApplication 的键窗口上添加了contentView。如果是这种情况,那么模态视图控制器将始终位于弹出窗口下方。您可以通过向KGModal 类添加新方法来解决此问题

- (void) showWithContentView: (UIView*)           contentView
            inViewController: (UIViewController*) controller
                 andAnimated: (BOOL)              animated;

该方法应在指定控制器的视图中显示弹出窗口;你应该改用那个方法。

编辑

经过一番挖掘,我发现KGModal 在另一个窗口中显示了弹出窗口。最快的解决方法是关闭弹出窗口,然后显示导航控制器。

【讨论】:

  • 如何关闭弹出窗口并立即显示导航控制器?
  • 使用 [[KGModal sharedInstance] hideAnimated];
  • 但是有没有办法显示 navController 以便它出现在弹出窗口的顶部?因为我不希望弹出窗口关闭并出现 nacController。我希望出现 navController 并且弹出窗口仍然存在。如果你能给我一些示例代码,我会很高兴。
猜你喜欢
  • 1970-01-01
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
  • 2012-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多