Question

[self setTransform:CGAffineTransformIdentity];
[self setFrame:CGRectMake(o.x, o.y, width, self.frame.size.height)];
if(width != 0)
{
   self.layer.anchorPoint=CGPointMake((wsCollectionView_CellSize/2)/width, 0.5);
}
[self setTransform:CGAffineTransformMakeRotation(angle)];

Im using this code to change the look of my view, however when this code is executed i can see little blinking near the anchor point, like its being adjusted, i think this is because when i set new frame, then new anchor point is set and it is being redrawn. So im guessing what i need is to execute this at the same time or those properties must be set simultaneously. What is the way to achieve that? or may be there is a way to set anchor in points and it will be constant?

Était-ce utile?

La solution

The anchorPoint of a layer is an animatable property. This means, if you just set it, then the layer will animate to the new value by default. This animation is likely to generate the flickering you are seeing as the anchor point fights against the transforms you are making.

To prevent this, you need to make the update inside a CATransaction with actions disabled:

[CATransaction begin];
[CATransaction setDisableActions:YES];
layer.anchorPoint = ...
[CATransaction commit];

This will immediately update the anchor point of your layer.

Normally, updating the anchor point also updates the frame of the view as well, so you'd normally want to set the frame after you've set the anchor point! unless this is already taken into account in the code above.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top