CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
12k stars 1.26k forks source link

Trouble adding UiVisualEffectView to SideNavigationViewController #119

Closed gorgamore closed 8 years ago

gorgamore commented 8 years ago

Im having a little bit of trouble adding a UiVisualEffectView (specifically a blur) as the background to the SideViewController. The blur renders fine until I scroll the contents of the table view. Thats when these random artifacts start to render. it I dont set the text of the label no artifacts form when scrolled. Im sorry if this is a trivial issue.

screen shot 2016-01-13 at 10 12 18 pm screen shot 2016-01-13 at 10 12 07 pm

daniel-jonathan commented 8 years ago

Hi, please provide the code you are using to apply the visual effect.

gorgamore commented 8 years ago

this is how Im adding the blur view

let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView
            visualEffectView.frame = self.view.bounds
            visualEffectView.autoresizingMask = [.FlexibleHeight , .FlexibleWidth]
            self.view.clipsToBounds = false
            self.view.layer.masksToBounds = false
            self.view.addSubview(visualEffectView)

Im calling the above code during viewDidLoad of the SideViewController.

daniel-jonathan commented 8 years ago

Best would be to send me a project where I can reproduce the issue. You can send it to support@cosmicmind.io

gorgamore commented 8 years ago

Just sent the project over. I was testing using the storyboard sample you've provided. Thank you for being so willing to help. Ive spent quite something already trying to figure this out so this was my last resort.

daniel-jonathan commented 8 years ago

No worries. This is what we are here to do :)


Daniel Dahan

M: +1 647.627.0770 Skype: djondahan

On Jan 14, 2016, at 11:19 AM, Marcoaferrer notifications@github.com wrote:

Just sent the project over. I was testing using the storyboard sample you've provided. Thank you for being so willing to help. Ive spent quite something already trying to figure this out so this was my last resort.

— Reply to this email directly or view it on GitHub https://github.com/CosmicMind/MaterialKit/issues/119#issuecomment-171688084.

daniel-jonathan commented 8 years ago

I'll be looking at your issue in a couple hours. Shouldn't take long to have an answer for you.

daniel-jonathan commented 8 years ago

So the issue is the shadow effect that is behind the sideNav. You need to set it to .None.

Add this code to the SideViewController.

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    sideNavigationViewController?.backdropColor = nil
    sideNavigationViewController?.depth = .None
}

The other thing you may want to do is remove the backdropColor. That can be done by adding this value to the viewWillAppear method, which I did above.

sideNavigationViewController?.backdropColor = nil

Then, in the prepareTableView method, add this code, which properly sets up the blurEffect.

if !UIAccessibilityIsReduceTransparencyEnabled() {
    tableView.backgroundColor = UIColor.clearColor()
    let blurEffect = UIBlurEffect(style: .Light)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    tableView.backgroundView = blurEffectView

    //if you want translucent vibrant table view separator lines
    tableView.separatorEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
}

And last of all, you may need to set the cell backgroundColor to a clear color.

cell.backgroundColor = MaterialColor.clear

I truly wish this question was on Stack as many people could benefit from the answer. You inspired me to make a cool example using these effects. I will launch that shortly.

If you have any other issue please reopen or create a new ticket.

All the best!

gorgamore commented 8 years ago

It works perfectly now. Thanks a ton. I look forward to seeing the new example.