2012-04-05 18 views
0

に呼び出されます: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]; 

を使用しなければならないことであるだけでアイデアわからない

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

1

のようなものを使用してみてください'used'行列を乗算してそれを乗算します。

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