Question

I have a brief for a share page which involves clicking on a share button and a modal view appearing over the top with some share functionality.

My issues is that i'd like the background of the modal view to be semi transparent and therefore show the view beneath. I've set the background properties of the modal layer and as the modal appears the layer beneath is briefly visible - and looks exactly as I require - but as soon as the cover transition is complete the background view is hidden - is there any way around this?

(Using IOS7 by the way)

Cheers

Update - @Tommaso Resti has kindly helped me try and figure this issue out - to explain what I've done so far - my main storyboard contains an unlinked uiview with the identifier 'ShareScreenView' - which I would like to add to my mainView as a transparent modal when clicking on a button. I have linked the button as an IBAction and added the following to my method -

- (IBAction)shareBtn:(id)sender {


    NSLog(@"clicked");



    /* Create your view off the screen (bottom) */

    /* NEW EDIT */
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"
                                                         bundle: nil];
    UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ShareScreenView"];

    [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)];
 // [myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height])];


 /* Animate it from the bottom */
 [UIView animateWithDuration:.5 animations:^{
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myModalController.view.transform = move;   /* UPDATED HERE */
     NSLog(@"Atrying");
 } completion:^(BOOL finished) {
    NSLog(@"Adid try");
    if(finished) {
        NSLog(@"Animation completed");
    }
 }];

} 

But I get an error on the line -

[myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height])];

which simply states 'expected identifier' with an arrow pointing at height (see screen shot below)

enter image description here

so I tried adding the properties as follows -

 [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)];

now there are no errors - but nothing happens and no errors..

Was it helpful?

Solution

i suggest to use your own method:

something like this:

/* Create your view off the screen (bottom) */

/* NEW EDIT */
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                     bundle: nil];
UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyModalController"];
[myModalController.view setFrame: CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view addSubview: myModalController.view]; /* UPDATED HERE! */


/* Animate it from the bottom */
[UIView animateWithDuration:.5 animations:^{
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myModalController.view.transform = move;   /* UPDATED HERE */
} completion:^(BOOL finished) {
    if(finished) {
        NSLog(@"Animation completed");
    }
}];

than remove with this animation:

/* Reset animation */
[UIView animateWithDuration:.5 animations:^{
    CGAffineTransform reset = CGAffineTransformIdentity;
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myModalController.view.transform = reset;  /* UPDATED HERE */
} completion:^(BOOL finished) {
    if(finished) {
        NSLog(@"Reset completed");
        [myModalController.view removeFromSuperview];
    }
}];

--- EDITED --- Sorry, i forgot to add ".view " after myViewController. i never try my code... my fault ;)

The example is updated!

OTHER TIPS

You can create a View, which you slide in from the bottom and then make the view semi transparent.

You can use View Container to create your own ModalViewController and do animation just like @Tommaso Resti says

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top