开发者

Is this view style possible?

开发者 https://www.devze.com 2023-03-09 03:14 出处:网络
I need a screen like this: Always on the top, there\'s a search bar, Always. Right beneath, there\'s a navigation controller. Is this possible? I have tr开发者_运维百科ied resizing the navigation cont

I need a screen like this: Always on the top, there's a search bar, Always. Right beneath, there's a navigation controller. Is this possible? I have tr开发者_运维百科ied resizing the navigation controller in IB but I can't re-size it. Thanks.


Yes. You will have to construct the interface in code, however. Your main view controller should have two instance variables: the first should be a search bar, and the second should be a navigation controller. Then, in -viewDidLoad, add the search bar and the navigation controller's view as subviews to the main view controller's view. The result will look like this:

Is this view style possible?

You can download the Xcode project here: http://www.mediafire.com/?36dswv4u0le447k


It's not exactly simple, but this is possible. What you need to do is make the root view controller a plain view controller, containing a UIView. That view contains the search bar and a "holder view". At the point where you would add the nagivigation controller's view to the window, you instead add it to the holder view.

Is this view style possible?

I created this using the standard navigation controller template. I modified the app delegate as follows:

//header
{
    UIWindow *window;
    UINavigationController *navigationController;
    UIViewController *rootVC;
    UIView *holderView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIViewController *rootVC;
@property (nonatomic, assign) IBOutlet UIView *holderView;

//implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    UIView *temp;
    temp = navigationController.view;
    CGRect f = holderView.frame;
    f.origin = CGPointZero;
    temp.frame = f;
    [holderView addSubview:temp];
    [window addSubview:rootVC.view];
    [window makeKeyAndVisible];
    return YES;
}

An image of the IB hierarchy:

Is this view style possible?

0

精彩评论

暂无评论...
验证码 换一张
取 消