简体   繁体   中英

How to disable background view with dark transparent color?

I created animation for a uiview that slides from the bottom of the screen, but i want after the view slides on to the screen to make the bg view disabled and with dark bg like this:

在此输入图像描述

How can i do this? Also when i tap the dark transparent view i want it to slide out and to make the bg view enabled.

this is how I do the sliding animation:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {

    } else if (buttonIndex == 1) {

        self.slidingView.hidden = NO;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        self.slidingView.frame = CGRectMake(0,0,320,20);
        self.view.frame = CGRectMake(0,0,320,460);
        [UIView commitAnimations];
        self.view.userInteractionEnabled = NO;
    }
}

Thanksss

I did a similar thing on a recent project. Instead of adding only one view which is the view that contains the picker, add a parent view to it. So what you will be adding to your view controller is a view that will be the size of your screen with a transparent black background and then add to it a subview the view with your picker with your custom animation.

Another way to do this is to have a view in your view controller that is initially hidden and when you show your picker view you show it.

I can help you better if you can share your code.

Edit:

-add a view in your view controller with the same width and height, with leading, top, trailing and bottom constraints.

-have an outlet for this view (ex:backgroundView)

-in your viewDidLoad: add the following line:

self.backgroundView.hidden=YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourcodeToCloseTheView)];
singleTap.numberOfTapsRequired = 1;
[self.backgroundView addGestureRecognizer:singleTap];

-and in your actionSheet:clickedButtonAtIndex: add this line:

self.backgroundView.hidden=NO;

Just make sure that the backgroundView is behind your pickerView in IB.

Hope that helps

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