我需要添加视图的句柄(角落),以便用户可以使用它们调整此视图的大小。类似于在Apples'pages'或'keynote'应用程序中编辑图形的东西。 (或任何其他图形应用程序)。 我确实尝试将句柄子视图添加到给定视图,但这些视图仅在两个重叠的位置接触,在给定的视图边界内。我需要能够拖动任何角落手柄,这将改变给定视图的框架或边界。 (这部分我已经在工作了。)
任何建议,教程,链接将不胜感激:)
我是新人,所以我不能:(发布图片,所以 please take a look at link
答案 0 :(得分:2)
我会创建一个UIGripView,它继承自你想要的视图之上的UIView。
它会:
-(void) drawRect:(CGRect)rect
如果您将每个手柄都设为UIView,也可以更轻松地处理手势,但是在您的视图中制作一些区域并检查触摸是哪个区域并不难。
(请记住使触摸区足够大)
答案 1 :(得分:1)
- (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);
}
}