動畫

2013-03-16 55 views
2

註冊我的查看與UISwipeGestureRecognizer來識別向左或向右滑動過程中如何獲得frame.width。和響應操作:動畫

[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動畫時這樣做呢?

+0

的NSLog(@ 「%@」,NSStringFromCGSize(sliderImageView.frame.size)); – 2013-03-16 07:37:55

+0

它不起作用。打印的尺寸可能是{0,26}或{199} 26:?(@蘇雷什 – rob2468 2013-03-16 08:21:04

回答

3

在動畫,您可以訪問使用視圖的層的表示層屬性的當前值。在項目中包含的QuartzCore框架,導入QuartzCore頭,並使用此:

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

參考here

+0

啊哈,這是great.'CALayer * TEMP = self.sliderImageView.layer.presentationLayer; 的NSLog(@ 「%@」,NSStringFromCGSize(temp.frame.size) );' – rob2468 2013-03-16 08:54:00

0

你會得到這樣的:

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

是它的工作 – Balu 2013-03-16 07:36:28

+0

不工作,我想我已經改變了寬度,所以無論我做什麼,以獲得寬度爲。改變後的值,可能需要一些潛在的方法來使它 – rob2468 2013-03-16 08:25:56