ios - 使用 CGAffineTransform 旋转后 UIView 调整大小 View 大小是不可预测的

标签 ios uiview cgaffinetransform rotatetransform

Possible Duplicate:
Weird behavior of UIView frame after rotation in iPhone

我正在开发一个应用程序,它具有旋转 View 和调整 View 大小的功能。我已经实现了这个功能,但我确实遇到了一个问题。

我的问题

拖动 View 的四个角时, View 将被调整大小,调整大小后,我可以双向旋转 View 。

旋转完成后,如果我再次尝试通过拖动 View 的角来调整 View 的大小, View 的大小会变成不可预测的值,并且会在屏幕上移动。

类似问题

我用谷歌搜索了很多,但没有得到任何完美的答案。有些人问了同样的问题,但没有人得到任何好的结果。我花了很多时间,但无法解决它。请帮帮我 以下是类似问题的列表:

similar question link : 1

similar question link : 2

我的示例代码

link

调整 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/

相关文章:

ios - UITableViewCell : Allowing Selective Deletion

ios - Estimote SDK 的 undefined symbol 链接器失败

iphone - 如何检测 subview 中的触摸事件或当我们触摸 subview 时如何使父 View 被触摸?

ios - CALayer 未在 View 中正确定位

objective-c - 如何应对点击速度过快的用户

ios - CGAffineTransform 动画没有在正确的位置结束

swift - View 旋转后移动 View , View 中触摸位置错误

ios - 找不到子项目(框架)的模块

ios - 避免插页显示该应用程序是否是通过 App Store 应用程序购买的

ios - UIBezierPath 不使用 applyTransform 方法旋转