简体   繁体   English

如何禁用深色透明色的背景视图?

[英]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: 我为从屏幕底部滑动的uiview创建了动画,但是我希望在视图滑动到屏幕上以禁用bg视图并使用这样的暗bg:

在此输入图像描述

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. 此外,当我点击暗透明视图时,我希望它滑出并启用bg视图。

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 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) - 有这个视图的出口(例如:backgroundView)

-in your viewDidLoad: add the following line: -in viewDidLoad:添加以下行:

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: - 并在您的actionSheet:clickedButtonAtIndex:添加以下行:

self.backgroundView.hidden=NO;

Just make sure that the backgroundView is behind your pickerView in IB. 只需确保backgroundView位于IB中的pickerView后面。

Hope that helps 希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据背景颜色自动更改视图的透明颜色 - How to automatically change transparent color of a view based on the color of it’s background 在iOS 7中,如何使导航栏具有深色背景颜色,但又具有透明性和模糊性呢? - In iOS 7, how do I have a nav bar with a dark background color, but have it transparent and blurred? SwiftUI 视图背景中的 UITextView 和暗模式(表单)的边框颜色 - UITextView inside a SwiftUI view background and border color for dark mode (Form) 如何加载具有透明背景色的UIViewController? - How to load UIViewController with transparent Background color? 如何在UIImageView中设置透明背景色 - How to set transparent background color in UIImageView 如何删除 UIImage 背景颜色并使其透明? - How to remove UIImage Background color and make it transparent? 如何在通知内容扩展中为我的自定义视图应用自定义字体/颜色和半透明背景? - How to apply custom font/color and semi-transparent background for my custom view in notification content extension? 当另一个视图显示时,如何使我的背景视图变暗? - How to make my background view to be dark when the another view is showing? AdMob横幅视图背景颜色为黑色,希望为白色或透明 - AdMob banner view background color is black, want white or transparent 背景透明的颜色 - Background transparent color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM