gpt4 book ai didi

ios - 如何通过拖动 ImageView 的右角来调整 ImageView 的大小和旋转 ImageView

转载 作者:行者123 更新时间:2023-11-29 04:24:21 29 4
gpt4 key购买 nike

您好,我有一个要求,我需要通过拖动 ImageView 的右角来调整 ImageView 的大小和旋转 ImageView 。

我可以通过拖动 ImageView 的角成功地调整 ImageView 的大小,但当我尝试用一​​根手指为 ImageView 实现调整大小兼旋转功能时失败。

任何人都可以指导我实现我的要求吗?

我添加了下面的代码,用于从角边缘调整 ImageView 的大小。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
touchStart = [[touches anyObject] locationInView:self];
isResizingLR = (self.bounds.size.width - touchStart.x < kResizeThumbSize && self.bounds.size.height - touchStart.y < kResizeThumbSize);
isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize);
isResizingUR = (self.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize);
isResizingLL = (touchStart.x <kResizeThumbSize && self.bounds.size.height -touchStart.y <kResizeThumbSize);

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint touchPoint = [[touches anyObject] locationInView:self];
CGPoint previous=[[touches anyObject]previousLocationInView:self];

float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;

if (isResizingLR) {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);
}
if (isResizingUL) {
self.frame = CGRectMake(self.frame.origin.x + deltaWidth, self.frame.origin.y + deltaHeight, self.frame.size.width - deltaWidth, self.frame.size.height - deltaHeight);
}
if (isResizingUR) {
self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y + deltaHeight, self.frame.size.width + deltaWidth, self.frame.size.height - deltaHeight);
}
if (isResizingLL) {
self.frame = CGRectMake(self.frame.origin.x + deltaWidth ,self.frame.origin.y , self.frame.size.width - deltaWidth, self.frame.size.height + deltaHeight);
}

if (!isResizingUL && !isResizingLR && !isResizingUR && !isResizingLL) {
self.center = CGPointMake(self.center.x + touchPoint.x - touchStart.x,self.center.y + touchPoint.y - touchStart.y);
}

}

最佳答案

您好,通过此代码示例调整 UIImageView 的大小 Here

试试这个...

希望对你有帮助...

试试这个旋转...

self.imgViewForBend.layer.anchorPoint = CGPointMake(0.0,1.0);
self.imgViewForBend.layer.position = CGPointMake(200,300.0);
CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(-(3.141/4));
[self.imgViewForBend setTransform:cgaRotateHr];

关于ios - 如何通过拖动 ImageView 的右角来调整 ImageView 的大小和旋转 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12560973/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com