Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with UIVisualEffectView as background #5

Open
maciejburda opened this issue Feb 24, 2015 · 6 comments
Open

Problem with UIVisualEffectView as background #5

maciejburda opened this issue Feb 24, 2015 · 6 comments

Comments

@maciejburda
Copy link

I wanted to add finaly efficent bluring technique added in iOS8 - UIVisualEffectView to collectionViewCell, but there is something wrong with rendering it in every second cell.

I am not that fluent with layout so I decided to ask you to have a look.
I define blur background like this inside cell:

-(void)setupBlurView
{
    if ([self.blurEffectView superview]) {
        [self.blurEffectView removeFromSuperview];
    }
    self.blurEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    self.blurEffectView.frame = self.bounds;
    [self insertSubview:self.blurEffectView atIndex:0];
}

Any ideas what causes it?

@terminatorover
Copy link
Owner

Is this code inside your custom collectionVIewCell ? if so you should probably add the blur effect view into the the contentView of the cell instead of directly inserting it to the cell.

@maciejburda
Copy link
Author

This code is executed in

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setupBlurView];
}

of the custom collection view cell using

[collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath];

The reason why I dare to blame your awesome layout is that when I disable it I don't get this kind of artifacts.

Please have a look at the screenshot.
Bare in mind it happens to every other (1,3,5,7 ...) cell. Maybe there is something diffrent with their apperance?
ios simulator screen shot 24 feb 2015 18 04 01
ios simulator screen shot 24 feb 2015 18 03 58
ios simulator screen shot 24 feb 2015 18 04 10

@terminatorover
Copy link
Owner

I see the screen shots and they seem fine to me. But maybe there is something i'm missing. What specifically about the screenshots you posted bothers you ? namely, what do you mean by "artifacts" is it the actual transform ? have you checked out the video, in the readme of the repo, the transforms are part of what makes the layout. But I love how you are using it it with blur views, it makes for an interesting effect

@maciejburda
Copy link
Author

There is strong diffrence between left and right blur view. Left has artifacts (blur is distorted in some kind of wrong way). It looks much worse when you are actually moving it around.

I understand how the layout works and I like 3D transition.
Probably I should blame apple for bug in uivisualeffectview.

But I wanted to talk about cell recreation and possible problems which it may cause to uivisualeffectview.
As mentioned before turing off the layout makes it work and also simple 3D transitions with uivisualeffectview not cause the problem.

Any idea where to start looking?

@terminatorover
Copy link
Owner

I see your point. I'll have to look into it for the layout. However, I'd say that you apply a similar transform (rotation around say the y axis) with different angles and see how the blur effect view behaves.

@maciejburda
Copy link
Author

Here is my test code for 3D transitions of this view. It seem to work fine on every axis.

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIVisualEffectView *blurView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    self.blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
    self.blurView.frame = CGRectMake(100, 100, 200, 200);
    [self.view addSubview:self.blurView];
    [self runSpinAnimationOnView:self.blurView duration:1 rotations:1 repeat:INFINITY];
}


- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = repeat;

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

@end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants