简体   繁体   中英

Load View Controller from storyboard with a particular size

I want to know if it is possible to load/present modally a UIViewController with a "free form" size like the image below

在此处输入图片说明

I want to load the red one allways on top (allways visible) and interact with the ViewController below (blue one) at the same time.

EDIT: what i want is to show and hide FROM APP DELEGATE a small view controller to controll the music in my app. I was trying with a xib file with a custom UIViewController as the file owner (see image below). The xib is being showed right the way i want, but the UIViewController associated to it, id doesn't load and i don't know why...

在此处输入图片说明

So i thought to do it with a UIViewController free formed but im not making it and i don't know wich is the best way

EDIT2:

With the xib file way i did the next:

In AppDelegate i have a function showPlayer that is called with local notification to show the xib

-(void)showPlayer:(int)tag andObjetoCancion:(NSArray *)objetoCancion
{

ZocaloPlayerViewController *vc = [[ZocaloPlayerViewController alloc] initWithNibName:@"ZocaloPlayerView" bundle:nil];
[vc setObjectoCancion:[objetoCancion mutableCopy]];

if (globals.isPlaying) {
    [vc setCambiar:YES];
}else{
    [vc setCambiar:NO];
}

//here playerView is a UIView initiated in didFinishLaunchingWithOptions
if (playerView == nil) {
    playerView = [[UIView alloc] initWithFrame:CGRectMake(0,  self.window.frame.size.height, self.window.frame.size.width, altoPlayer)];
}

//keyWindow is UIWindow
//NSLog(@"Abro view %ld", (long)viewPlayer.tag);
keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:playerView];
[keyWindow bringSubviewToFront:playerView];


NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"ZocaloPlayerView" owner:vc options:nil];
mainView = [subviewArray objectAtIndex:0];
mainView.translatesAutoresizingMaskIntoConstraints = NO;  //This part hung me up


[playerView addSubview:mainView];

//needed to make smaller for iPhone 4 dev here, so >=200 instead of 748
[playerView addConstraints:[NSLayoutConstraint
                           constraintsWithVisualFormat:@"V:|-0-[mainView]-0-|"
                           options:NSLayoutFormatDirectionLeadingToTrailing
                           metrics:nil
                           views:NSDictionaryOfVariableBindings(mainView)]];

[playerView addConstraints:[NSLayoutConstraint
                           constraintsWithVisualFormat:@"H:|-0-[mainView]-0-|"
                           options:NSLayoutFormatDirectionLeadingToTrailing
                           metrics:nil
                           views:NSDictionaryOfVariableBindings(mainView)]];

[UIView animateWithDuration:0.3 animations:^{
    playerView.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - mitadAltoPlayer);
    [self.window layoutIfNeeded];
}];

}

ZocaloPlayerViewController *vc is being instantiated but the viewDidLoad function inside it is not being called.... That is my first problem...

With the UIViewController free formed way i don't know how to do it...

Ok, i solved my problem with this post Loaded nib but the view outlet was not set - new to InterfaceBuilder (i was missing the UIView outlet)

and i changed my code in the showPlayer function to this:

-(void)mostrarPlayer:(int)tag andObjetoCancion:(NSArray *)objetoCancion
{

ZocaloPlayerViewController *vc = [[ZocaloPlayerViewController alloc] initWithNibName:@"ZocaloPlayerView" bundle:nil];
[vc setObjectoCancion:[objetoCancion mutableCopy]];

if (globals.isPlaying) {
    [vc setCambiar:YES];
}else{
    [vc setCambiar:NO];
}


if (playerView == nil) {
    playerView = [[UIView alloc] initWithFrame:CGRectMake(0,  self.window.frame.size.height, self.window.frame.size.width, altoPlayer)];
}

//NSLog(@"Abro view %ld", (long)viewPlayer.tag);
keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:playerView];
[keyWindow bringSubviewToFront:playerView];

[playerView addSubview:vc.view];

[UIView animateWithDuration:0.3 animations:^{
    playerView.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - mitadAltoPlayer);
    [self.window layoutIfNeeded];
}];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM