I am designing an alert view in which I display a custom view when user taps a particular button.I am using a scroll view for my lengthy content view. I have written the code for the same as given below.
I want that this alert view to display right in the middle of your display screen irrespective of scroll position or content view position as alert in iOS by default pop ups. So is there any way to do that. I have tried a way but didn't succeed.
And the only solution I found is to scroll to top before displaying and add the subview. And since this is not perfect,so please suggest some measures or suggestions. Thanks.
@IBAction func forgotpassword(sender: AnyObject)
{
blurEffect = UIBlurEffect(style: .Dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.contentview.bounds
blurEffectView.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]
self.AlertVieww.frame.size = CGSizeMake(blurEffectView.frame.width-40, self.AlertVieww.frame.height)//AlertVieww is the IBOutlet of my custom view in scene dock
AlertVieww.center = CGPointMake(UIScreen.mainScreen().bounds.size.width/2, UIScreen.mainScreen().bounds.size.height/2);
AlertVieww.autoresizingMask = [.FlexibleHeight,.FlexibleWidth]
blurEffectView.addSubview(self.AlertVieww)
[self.scrollview.setContentOffset(CGPointZero, animated: false)]//I scroll to the top
UIView.transitionWithView(self.view, duration: 1.0, options: UIViewAnimationOptions.TransitionFlipFromBottom, animations:
{
self.contentview.addSubview(self.blurEffectView)
}, completion: { finished in
self.scrollview.scrollEnabled = false
})
}
//These are two cnacel buttons in which I remove the views
@IBAction func sendAlert(sender: AnyObject)
{
self.blurEffectView.hidden = true
self.scrollview.scrollEnabled = true
}
@IBAction func cancelAlert(sender: AnyObject)
{
self.blurEffectView.hidden = true
self.scrollview.scrollEnabled = true
}