Padavan
Padavan

Reputation: 1074

Add a subview to MasterView of UISplitViewController

I need to add a subview to left part of UIViewController, which shows the user that there is something near the left part of screen, when masterview is hidden(in portrait orientation). And this view must move with left part of UISplitView. Something like the view with arrow in these two images. (Sorry for the russian interface) http://s2.uploads.ru/8EHJI.png http://s2.uploads.ru/NhEam.png But my problem is that when I try to add such a view, it clips to bounds of masterview and is not visible when masterview is hidden. I think, I'm doing it wrong and there is an easy way to do this.

Update: I've tried to make some hack like:

-(void) clipToBoundsRecursive:(UIView *)someView
{
    NSLog(@"%@", someView);
    someView.clipsToBounds = NO;
    for (UIView *v in someView.subviews)
    {
        [self clipToBoundsRecursive:v];
    }
}

and send it to view of splitviewcontroller.

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
[self clipToBoundsRecursive:splitViewController.view];

It takes effect at first time (subviews outside the masterview's bounds shows, but after first show/hide animation they disappears and don't appear even if I call this method again)

Upvotes: 3

Views: 1323

Answers (4)

Undo
Undo

Reputation: 25697

Sounds to me like your app could benefit from PKRevealController.

Upvotes: 2

Rafeek
Rafeek

Reputation: 533

Try with deselecting auto layout option in identity and type pan if you are using nib otherwise set autoresizing mask to view that currently clipping. I believe it will solve the issue

Upvotes: 1

iPatel
iPatel

Reputation: 47069

I have described here a simple Logic for you: (how to add a UIView in Window and call it from your master or detail view )

Create UIView in #import "AppDelegate.h" ,

- (void) CreateViewInWindow
{
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 780)];// set as u wish
    myView.backgroundColor = [UIColor redColor];

    // I have added myView to the Window with a specific animation , your can give animation as you like. :)
    [UIView transitionWithView:self.window duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve // change to whatever animation you like
                    animations:^ { [self.window addSubview:myView]; }
                    completion:nil];
}

Here create a simple UIButton in the DetailViewController.m file (You can put the code in either of the files, DetailViewController.m OR MasterViewController.m)

UIButton *btnShowView = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnShowView addTarget:self action:@selector(btnShowViewTapped:) forControlEvents:UIControlEventTouchUpInside];
btnShowView.frame = CGRectMake(20, 30, 174, 35);
//[btnLoginInner setBackgroundImage:[UIImage imageNamed:@"LoginBut.png"] forState:UIControlStateNormal];
[self.view addSubview:btnShowView];

In button tapped method, write code for calling UIView from AppDelegate, and also don't forget to add #import "AppDelegate.h" in DetailViewController.m,

-(void)btnShowViewTapped:(UIButton *) Sender
{
    AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [del performSelector:@selector(CreateViewInWindow) withObject:nil afterDelay:0];
}

Above code is a simple logic for your problem, It might be helpful for you.

Upvotes: 3

Tim
Tim

Reputation: 14446

You can add the view directly to the window's view, though you will have to manually manage its position depending on when the device rotates. Views added to the window.view will appear above the rootViewController.view.

Upvotes: 6

Related Questions