0

I Have UiView(PromoView), I want to Open PromoView on UIButton's Action, also set Background Blur when popup view is open and when user click anywhere in view the PoPView will be hidden. this is my code..

-(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){
  }];
}

Its just open with animation, help me with code...

Ketan Odedra
  • 1,215
  • 10
  • 35

2 Answers2

2

In viewDidLoad add UITapGestureRecognizer to the view

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;

}
Clown
  • 163
  • 1
  • 12
  • This is blur view code, Use search before asking question https://stackoverflow.com/questions/17041669/creating-a-blurring-overlay-view – Clown Oct 03 '17 at 07:48
  • Also, alertview is a pop-up what do you mean? You can use UIViewAnimation and try which one is suits for you. – Clown Oct 03 '17 at 07:50
1

Try this,

@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
    }
}

Hope this work!

Judit
  • 41
  • 4