Ios 在UIView上显示UIView,就像在UIView上单击PopUpView按钮一样?
我有UiView(PromoView), 我想在UIButton的操作上打开PromoView,当弹出视图打开时,也设置背景模糊,当用户单击视图中的任何位置时,弹出视图将被隐藏。 这是我的密码Ios 在UIView上显示UIView,就像在UIView上单击PopUpView按钮一样?,ios,objective-c,uiview,popup,Ios,Objective C,Uiview,Popup,我有UiView(PromoView), 我想在UIButton的操作上打开PromoView,当弹出视图打开时,也设置背景模糊,当用户单击视图中的任何位置时,弹出视图将被隐藏。 这是我的密码 -(IBAction)PromoCode_btn:(id)sender { _PromoView.hidden=NO; _PromoView.transform = CGAffineTransformMakeScale(0.01, 0.01); [UIView animateWit
-(IBAction)PromoCode_btn:(id)sender
{
_PromoView.hidden=NO;
_PromoView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.view.alpha=0.5;
_PromoView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
}];
}
它只是用动画打开,
帮助我在
viewdiload
中将UITapGestureRecognizer
添加到视图中的代码…
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[_PromoView addGestureRecognizer:singleFingerTap];
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer{
//Do animation here...
_PromoView.hidden = YES;
}
在
viewdiload
中将uitappesturerecognizer
添加到视图中
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[_PromoView addGestureRecognizer:singleFingerTap];
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer{
//Do animation here...
_PromoView.hidden = YES;
}
试试这个
@IBAction func PromoCode_btn(_ sender: Any) {
view_background.backgroundColor = UIColor.black
view_background.alpha = 0.8
view_background.translatesAutoresizingMaskIntoConstraints = false
layoutDic["view_background"] = view_background
self.view.addSubview(view_background)
view_background.isHidden = false
self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view_background]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricdict, views: layoutDic))
self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view_background]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricdict, views: layoutDic))
let promoHideTap = UITapGestureRecognizer.init(target: self, action: #selector(self.promoCancelAction))
promoHideTap.delegate = self
view_background.addGestureRecognizer(promoHideTap)
_PromoView.translatesAutoresizingMaskIntoConstraints = false
layoutDic["_PromoView"] = _PromoView
view_background.addSubview(_PromoView)
_PromoView.backgroundColor = UIColor.white
_PromoView.layer.borderColor = UIColor.lightGray.cgColor
_PromoView.layer.borderWidth = 0.2
_PromoView.layer.shadowColor = UIColor.gray.cgColor
_PromoView.layer.shadowOpacity = 0.2
view_background.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-200-[_PromoView(300)]", options: NSLayoutFormatOptions(rawValue: UInt(0)), metrics: metricdict, views: layoutDic))
view_background.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-250-[_PromoView]-250-|", options: NSLayoutFormatOptions(rawValue: UInt(0)), metrics: metricdict, views: layoutDic))
}
func promoCancelAction()->Void
{
view_background.isHidden = true
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
{
// Method to recognize whether the tap originated from bg view or table view
if touch.view!.isDescendant(of: _PromoView)
{
return false
}
else
{
return true
}
}
希望这项工作 试试这个
@IBAction func PromoCode_btn(_ sender: Any) {
view_background.backgroundColor = UIColor.black
view_background.alpha = 0.8
view_background.translatesAutoresizingMaskIntoConstraints = false
layoutDic["view_background"] = view_background
self.view.addSubview(view_background)
view_background.isHidden = false
self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view_background]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricdict, views: layoutDic))
self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view_background]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricdict, views: layoutDic))
let promoHideTap = UITapGestureRecognizer.init(target: self, action: #selector(self.promoCancelAction))
promoHideTap.delegate = self
view_background.addGestureRecognizer(promoHideTap)
_PromoView.translatesAutoresizingMaskIntoConstraints = false
layoutDic["_PromoView"] = _PromoView
view_background.addSubview(_PromoView)
_PromoView.backgroundColor = UIColor.white
_PromoView.layer.borderColor = UIColor.lightGray.cgColor
_PromoView.layer.borderWidth = 0.2
_PromoView.layer.shadowColor = UIColor.gray.cgColor
_PromoView.layer.shadowOpacity = 0.2
view_background.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-200-[_PromoView(300)]", options: NSLayoutFormatOptions(rawValue: UInt(0)), metrics: metricdict, views: layoutDic))
view_background.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-250-[_PromoView]-250-|", options: NSLayoutFormatOptions(rawValue: UInt(0)), metrics: metricdict, views: layoutDic))
}
func promoCancelAction()->Void
{
view_background.isHidden = true
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
{
// Method to recognize whether the tap originated from bg view or table view
if touch.view!.isDescendant(of: _PromoView)
{
return false
}
else
{
return true
}
}
希望这项工作 可能重复的否,它是不同的。可能重复的否,它是不同的。这是模糊视图代码,在提问之前使用搜索,alertview是一个弹出窗口,你是什么意思?您可以使用UIViewAnimation并尝试哪一个适合您。这是模糊视图代码,在提问之前使用搜索,alertview是一个弹出窗口。您的意思是什么?您可以使用UIViewAnimation并尝试哪一个适合您。