2012-04-05 166 views
0

i之後調整照片,此方法被稱爲:setBound寬度和高度

- (void)correctSize:(UIView*)view{ 
    //check if the newWidth is rounded by 50 
    CGFloat correctWidth = roundf(_lastScale*_lastWidth/XPCollageGridHorizontalStepSize) * XPCollageGridHorizontalStepSize; 
    CGFloat correctHeight = roundf(_lastScale*_lastHeight/XPCollageGridVerticalStepSize) * XPCollageGridVerticalStepSize; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5f]; 
    [view setBounds:CGRectMake(view.bounds.origin.x, view.bounds.origin.y, correctWidth, correctHeight)]; 
    //[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, correctWidth, correctHeight)]; 
    [UIView commitAnimations]; 
} 

它舍入相片尺寸; 66的寬度將舍入到50,178到200等 它工作正常,當我使用setFrame方法,但因爲即時通訊也使用旋轉我想與setBounds一起工作。

當我使用setBounds時,視圖將調整大小,但不是調整爲像300這樣的舍入數字,而是將其大小調整爲隨機的311.23。

我在這裏錯過了什麼嗎?

回答

0

答案是,我必須使用

[view setTransform:CGAffineTransformIdentity]; 

現在利用其已經'使用'矩陣並將其與其相乘。

CGFloat correctWidth = roundf(_lastScale*_lastWidth/XPCollageGridHorizontalStepSize) * XPCollageGridHorizontalStepSize; 
CGFloat correctHeight = roundf(_lastScale*_lastHeight/XPCollageGridVerticalStepSize) * XPCollageGridVerticalStepSize; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[view setTransform:CGAffineTransformIdentity]; //!!this line is added! 
[view setBounds:CGRectMake(0, 0, correctWidth, correctHeight)]; 

[UIView commitAnimations]; 
1

使用類似的嘗試:

// see the values here 
NSLog(@"%f", correctWidth); 
NSLog(@"%f", correctHeight); 
view.frame = CGRectMake(view.bounds.origin.x, view.bounds.origin.y, correctWidth, correctHeight); 
// see the values given 
NSLog(@"%f", view.frame.size.width); 
NSLog(@"%f", view.frame.size.height); 

只是一個想法不知道這是否會工作