ViewController With Transparent Background Enterin

2019-07-20 13:00发布

I have this story board :

enter image description here

my first ViewController has PNG image as background programatically :

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]];
}

my second ViewController has transparent background by selecting Clear Color as Background property on Storyboard.

but when it runs on my iPod, it seems that my second ViewController has same background but pushing first ViewController background from right to left.

what I want to do is :

  1. when Segue detected, it will move all UI components on first ViewController from current position to left so it feels like its all being pushed by second ViewController (but not the background, I want to keep the background in its position).

  2. then, all UI components on second ViewController enters using Push Transition which I already set on Storyboard as transparent ViewController.

So, it will gives smooth transition from one ViewController into another without moving the background.

I tried using this code :

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"goToViewTwo"])
    {
        UIViewController *view2 = segue.destinationViewController;
        view2.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgleft"]];
    }
}

but I don't know how to move / animate all UI components (button, label, etc) to perform as I described. please kindly tell me what to do.. thank you.

2条回答
Fickle 薄情
2楼-- · 2019-07-20 13:38

In second viewController paste this source

self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalPresentationStyle = UIModalPresentationFormSheet;
查看更多
男人必须洒脱
3楼-- · 2019-07-20 13:56

I think you can do this by making both controllers have a transparent background, and adding the background image to the window instead.

查看更多
登录 后发表回答