2010-11-22 94 views
0

有一個按鈕,當我點擊按鈕時,我想旋轉圖像180,但它只適用於我第一次點擊該按鈕時,如何繼續旋轉圖像,謝謝提前? 下面是我的源代碼:如何繼續旋轉圖像

- (IBAction)touchButton_Refresh { 

photo *photos = [photoArray objectAtIndexhotoIndex]; 
NSData *xmlData = [NSData dataWithContentsOfFilehotos.localPath]; 
UIImage *image; 
if ([xmlData isKindOfClass:[NSData class]]) { 
image = [[UIImage imageWithData:xmlData] retain]; 
} 


SlideItem *slideItemRotate; 


if (toOrientation == 1 || toOrientation == 2) { 
slideItemRotate = [[SlideItem alloc] initWithFrame:CGRectMake(768*photoIndex, 0, 768, 980)]; 
} 
else if (toOrientation == 3 || toOrientation == 4) { 
slideItemRotate = [[SlideItem alloc] initWithFrame:CGRectMake(1024*photoIndex, 0, 1024, 700)]; 
} 


slideItemRotate.photoImageView.image = image; 

CGAffineTransform rotation = CGAffineTransformMakeRotation(3.14159265); 
[slideItemRotate.photoImageView setTransform:rotation]; 

[[[slideScrollView subviews] objectAtIndex:0] removeFromSuperview]; 

[slideScrollView addSubview:slideItemRotate]; 


[slideItemRotate release]; 


} 

回答

1

你來串聯變換分析,否則你只是一味地應用相同的旋轉(實際上沒有旋轉它更多)。因此,更換這些線路:

CGAffineTransform rotation = CGAffineTransformMakeRotation(3.14159265); 
[slideItemRotate.photoImageView setTransform:rotation]; 

與此:

CGAffineTransform rotation = CGAffineTransformConcat([[slideItemRotate photoImageView] transform], CGAffineTransformMakeRotation(3.14159265)); 
[slideItemRotate.photoImageView setTransform:rotation]; 

這實際上將串聯旋轉並保持圖像周圍旋轉。如果你總是繞180度旋轉,另一種方法是測試身份變換。如果視圖的變換是標識變換,則應用旋轉。如果不是,則將轉換重置爲標識轉換(有效地反轉進程)。