2012-04-05 167 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); 

只是一个想法不知道这是否会工作