我需要添加一个UIView作为显示UIImageview的UIView的子视图。我需要实现的是,当图像加载到我的UIIMageview中时,同时我显示UIView将其称为newView。一开始,我用静态大小190X170和alpha作为0.5显示它。一旦我点击我的手指在该视图上,它应该移动整个UIImageview。一旦它最后移动了,我就会采用相同的点来裁剪我的图像。现在我使用下面的代码完成移动部分。如何添加可移动UIView作为动态大小在运行时在目标C中的子视图?
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(newView.frame, touchLocation))
{
dragging = YES;
oldX = touchLocation.x;
oldY = touchLocation.y;
}
if (dragging)
{
newView.layer.borderColor = [UIColor clearColor].CGColor;
newView.layer.borderWidth = 1.0f;
CGRect frame = newView.frame;
frame.origin.x = newView.frame.origin.x + touchLocation.x - oldX;
x = frame.origin.x;
NSLog(@"x value : %d",x);
frame.origin.y = newView.frame.origin.y + touchLocation.y - oldY;
y = frame.origin.y;
NSLog(@"y value : %d",y);
newView.frame = frame;
}
oldX = touchLocation.x;
oldY = touchLocation.y;
}
我需要实现的是调整像UIScrollview那样的两根手指的UIView大小。我试图实现UIScrollview但它没有给我很好的效果。我试图实施 NSUInteger resizingMask = NSViewHeightSizable | NSViewWidthSizable; [self.view setAutoresizesSubviews:YES]; [newView setAutoresizingMask:resizingMask];
但徒劳无功。没有任何事情发生。
任何人都可以为我显示相同的路径。提前致谢。
总之你想实现图像裁剪功能? –
是的同一件事。在放大newView时,我需要调整裁剪区域的大小。 – Sarah