如何在动画期间获得frame.width

时间:2013-03-16 07:25:48

标签: ios animation

我使用UISwipeGestureRecognizer注册我的View以识别向左或向右滑动。响应操作是:

[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];

如果可以获得显示视图的self.sliderImageView.frame.width?因为我在使用NSLog(@"%f", self.sliderImageView.frame.size.width)的动画期间尝试这样做的是0或199.那么有什么方法可以获得frame.width吗?

2 个答案:

答案 0 :(得分:3)

在动画期间,您可以使用视图图层的表示层访问属性的当前值。在项目中包含QuartzCore框架,导入QuartzCore标头,并使用:

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

参考here

答案 1 :(得分:0)

你会这样:

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