rob2468
rob2468

Reputation: 23

How to get the frame.width during the animation

I register my View with UISwipeGestureRecognizer to recognize a left or right swipe. And the response operation is:

[UIView beginAnimations:@"slide" context:nil];
[UIView setAnimationDuration:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

CGRect frame = self.sliderImageView.frame;
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft )
{
    frame.size.width = 0;
    self.sliderImageView.frame = frame;
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
    frame.size.width = 199;
    self.sliderImageView.frame = frame;
}

[UIView commitAnimations];

If it's possible to get the self.sliderImageView.frame.width of the displaying View? Because what I try to do so during the animation using NSLog(@"%f", self.sliderImageView.frame.size.width) is either 0 or 199. So is there any methods to get the frame.width?

Upvotes: 2

Views: 437

Answers (2)

jrturton
jrturton

Reputation: 119242

During an animation, you can access the current value of properties using the view's layer's presentation layer. Include the QuartzCore framework in your project, import the QuartzCore header, and use this:

self.sliderImageView.layer.presentationLayer.frame.size.width

Reference here.

Upvotes: 3

Balu
Balu

Reputation: 8460

You'll get like this :

NSLog(@"%f",self.sliderImageView.frame.size.width);

Upvotes: 0

Related Questions