Possible Duplicate:
Weird behavior of UIView frame after rotation in iPhone
我正在开发一个应用程序,它具有旋转 View 和调整 View 大小的功能。我已经实现了这个功能,但我确实遇到了一个问题。
我的问题
拖动 View 的四个角时, View 将被调整大小,调整大小后,我可以双向旋转 View 。
旋转完成后,如果我再次尝试通过拖动 View 的角来调整 View 的大小, View 的大小会变成不可预测的值,并且会在屏幕上移动。
类似问题
我用谷歌搜索了很多,但没有得到任何完美的答案。有些人问了同样的问题,但没有人得到任何好的结果。我花了很多时间,但无法解决它。请帮帮我 以下是类似问题的列表:
我的示例代码
调整 View 大小的代码
触摸开始方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"[touch view]:::%@",[touch view]);
touchStart = [[touches anyObject] locationInView:testVw];
isResizingLR = (testVw.bounds.size.width - touchStart.x < kResizeThumbSize && testVw.bounds.size.height - touchStart.y < kResizeThumbSize);
isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize);
isResizingUR = (testVw.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize);
isResizingLL = (touchStart.x <kResizeThumbSize && testVw.bounds.size.height -touchStart.y <kResizeThumbSize);
}
触摸移动方法
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint touchPoint = [[touches anyObject] locationInView:testVw];
CGPoint previous=[[touches anyObject]previousLocationInView:testVw];
float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;
NSLog(@"CVTM:%@",NSStringFromCGRect(testVw.frame));
if (isResizingLR) {
testVw.frame = CGRectMake(testVw.frame.origin.x, testVw.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);
}
if (isResizingUL) {
testVw.frame = CGRectMake(testVw.frame.origin.x + deltaWidth, testVw.frame.origin.y + deltaHeight, testVw.frame.size.width - deltaWidth, testVw.frame.size.height - deltaHeight);
}
if (isResizingUR) {
testVw.frame = CGRectMake(testVw.frame.origin.x ,testVw.frame.origin.y + deltaHeight, testVw.frame.size.width + deltaWidth, testVw.frame.size.height - deltaHeight);
}
if (isResizingLL) {
testVw.frame = CGRectMake(testVw.frame.origin.x + deltaWidth ,testVw.frame.origin.y , testVw.frame.size.width - deltaWidth, testVw.frame.size.height + deltaHeight);
}
if (!isResizingUL && !isResizingLR && !isResizingUR && !isResizingLL) {
testVw.center = CGPointMake(testVw.center.x + touchPoint.x - touchStart.x,testVw.center.y + touchPoint.y - touchStart.y);
}
}
调整大小之前的第一步
其次,我调整大小并旋转它
第三,我尝试调整它的大小,但它又移回到原来的位置
这些是更新的屏幕供您引用...
最佳答案
根据 UIView
上的文档,当 transform != CGAffineTransformIdentity
时,frame
属性未定义。这一定是你的问题。
关于ios - 使用 CGAffineTransform 旋转后 UIView 调整大小 View 大小是不可预测的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12636028/