0

在我调整照片大小后调用此方法:

- (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。

我在这里错过了什么吗?

4

2 回答 2

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);

只是一个想法,不确定它是否可行

于 2012-04-05T10:32:34.547 回答
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];
于 2012-04-10T09:10:01.280 回答