Viv*_*k T 2 rotatetransform uiview cgaffinetransform ios
可能的重复:
iPhone 中旋转后 UIView 框架的奇怪行为
我正在开发一个应用程序,它具有旋转视图和调整视图大小的功能。我已经实现了这个功能,但我确实面临一个问题。
我的问题
拖动视图的四个角时,视图将被调整大小,调整大小后,我可以在两个方向上旋转视图。
旋转完成后,如果我再次尝试通过拖动视图的角来调整视图的大小,则视图的大小会变成不可预测的值,并且会在屏幕上移动。
类似问题
我用谷歌搜索了很多,但没有得到任何完美的答案。有些人问了同样的问题,但没有人得到任何好的结果。我花了很多时间,但无法解决它。请帮助我以下是类似问题的列表:
我的示例代码
调整视图大小的代码
触摸开始方法
- (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);
}
Run Code Online (Sandbox Code Playgroud)
触摸移动方法
- (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);
}
}
Run Code Online (Sandbox Code Playgroud)
调整大小之前的第一步
其次我调整大小并旋转它
第三,我尝试调整它的大小,但它又移回到原来的位置
这些是更新的屏幕供您参考...
| 归档时间: |
|
| 查看次数: |
3530 次 |
| 最近记录: |