こんにちは私のアプリの友達は、ユーザーが画像のサイズ変更、回転、反転を行えるようにしたいと考えています。ここでは、以下のコードを使用してサイズを変更しました。
CGFloat angleToRotate ;CGPoint currentTouchPoint,previousTouchPoint; UITouch *touch;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
touch = [[event allTouches] anyObject];
//if (![touch.view isKindOfClass:[vw class]]) {
touchStart = [[touches anyObject] locationInView:self];
kResizeThumbSize=15;
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{
UITouch *touch = [[event allTouches] anyObject];
currentTouchPoint = [touch locationInView:self.superview];
previousTouchPoint = [touch previousLocationInView:self.superview];
CGPoint touchPoint1 = [[touches anyObject] locationInView:self.superview];
CGPoint previous1=[[touches anyObject]previousLocationInView:self.superview];
CGPoint touchPoint = [[touches anyObject] locationInView:self];
CGPoint previous=[[touches anyObject]previousLocationInView:self];
float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;
float deltaWidth1 = currentTouchPoint.x-previousTouchPoint.x;
float deltaHeight1 = currentTouchPoint.y-previousTouchPoint.y;
CGFloat newW= self.superview.frame.size.width+deltaWidth1;
if (isResizingLR) {
self.superview.frame = CGRectMake(self.superview.frame.origin.x, self.superview.frame.origin.y,self.superview.frame.size.width+deltaWidth1,self.superview.frame.size.height+deltaHeight1);
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,self.frame.size.width+deltaWidth,self.frame.size.height+deltaHeight);
[self setNeedsDisplayInRect:CGRectMake(self.frame.origin.x, self.frame.origin.y,self.frame.size.width+deltaWidth,self.frame.size.height+deltaHeight)];
}
if (isResizingUL) {
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width - deltaWidth, self.frame.size.height - deltaHeight);
self.superview.frame = CGRectMake(self.superview.frame.origin.x + deltaWidth1, self.superview.frame.origin.y + deltaHeight1, self.superview.frame.size.width - deltaWidth1, self.superview.frame.size.height - deltaHeight1);
[self setNeedsDisplayInRect:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width - deltaWidth, self.frame.size.height - deltaHeight)];
}
if (isResizingUR) {
self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y, self.frame.size.width + deltaWidth, self.frame.size.height - deltaHeight);
self.superview.frame = CGRectMake(self.superview.frame.origin.x ,self.superview.frame.origin.y+deltaHeight1, self.superview.frame.size.width + deltaWidth1, self.superview.frame.size.height - deltaHeight1);
[self setNeedsDisplayInRect:CGRectMake(self.frame.origin.x ,self.frame.origin.y, self.frame.size.width + deltaWidth, self.frame.size.height - deltaHeight)];
}
if (isResizingLL) {
self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y , self.frame.size.width - deltaWidth, self.frame.size.height + deltaHeight);
self.superview.frame = CGRectMake(self.superview.frame.origin.x + deltaWidth1 ,self.superview.frame.origin.y , self.superview.frame.size.width - deltaWidth1, self.superview.frame.size.height + deltaHeight1);
[self setNeedsDisplayInRect:CGRectMake(self.frame.origin.x ,self.frame.origin.y , self.frame.size.width - deltaWidth, self.frame.size.height + deltaHeight)];
CGSize supersize=self.superview.frame.size;
NSLog(@"superview frame in resize: %@",NSStringFromCGSize(supersize));
}
if (!isResizingUL && !isResizingLR && !isResizingUR && !isResizingLL) {
CGPoint center = CGPointMake(CGRectGetMidX([self.superview bounds]), CGRectGetMidY([self.superview bounds]));
// [self.superview setContentMode:UIViewContentModeRedraw];
CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
CGFloat angleInRadians1 = atan2f(touchPoint.y - center.y, touchPoint.x - center.x) - atan2f(previous.y - center.y, previous.x - center.x);
[self.superview setTransform:CGAffineTransformRotate([self.superview transform], angleInRadians)];
}
}
ここでサイズを変更して回転させることができますが、回転後にサイズを変更すると、サイズ変更が何かをしているのを助けてください。