[英]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.