English 中文(简体)
同时有多个UIView控制器
原标题:Multiple UIViewControllers simultaneously

我希望在导航控制器中有一个UITableView,占据整个屏幕。我有一个较小的自定义UIView,它需要从底部向上滑动,将表视图压缩100个像素。自定义视图需要是静态的,而不是在用户浏览表视图时移动。我被告知不要让2个UIViewControllers(VC)在同一屏幕上管理视图。

目前,我的AppDelegate从VC向其窗口添加了一个子视图,然后用

[self addSubview:tablviewcontroller.view]; [self addSubview:customViewController.view];

应如何实施?

问题回答

the way I would structure this is as follows: have a UIViewController subclass whose view takes up the entire screen. It will have two subviews. First subview: The view of the UINavigationController that contains your table view controller. Second subview: the custom UIView.

让UINavigationController的框架最初设置为主视图控制器的视图的整个边界,以及屏幕可见区域下方的自定义视图的框架。

当您需要向上滑动视图时,请使用UIView动画通过降低高度来设置更改UINavigationController视图帧的动画,并通过将自定义UIView的y坐标更改为现在位于帧中来更改其帧。

可以您需要一个导航控制器,其根视图是一个表视图。然后,可能通过用户输入,您希望此表视图向上滑动100像素,然后在底部出现另一个视图。当另一个视图停留在那里时,用户可以继续使用表视图。

以下是我的操作方法:

创建一个通用视图控制器(让我们称之为NavigationWithAuxiliaryViewController)。这个类的根视图覆盖了所有的应用程序窗口。

该视图有一个<code>UINavigationController</code>的实例作为其属性,例如<code>navController</code>。它还有一个UIView(用于另一个视图)作为其属性(例如,auxView)。将另一个视图放置在底部。但是,此视图在默认情况下是隐藏的。此外,UINavigationController的根视图的框架覆盖了整个视图。

当您决定压缩表视图时,请修改UINavigationController的frame属性。做这样的事(不过不要这么难看):

if (slideViewOn) {
    [UIView beginAnimations:@"slideUp" context:nil];
    navController.view.frame = CGRectMake(0, 0, 320, 260);
    auxView.hidden = NO;
    [UIView commitAnimations];
} else {
    [UIView beginAnimations:@"slideDown" context:nil];
    navController.view.frame = CGRectMake(0, 0, 320, 480);
    auxView.hidden = YES;
    [UIView commitAnimations];
}

压缩整个导航/表格内容的最简单方法是修改导航控制器的整个框架,这就是为什么您需要一个单独的视图(在导航控制器之外)用于另一个视图。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签