在滚动视图内使用手势(通过手势将内容带出滚动视图)
在我的 UIScrollView 中我有一个视图。该视图中有几幅图像。我想将图像从滚动条(和视图)拖到主视图。然而,在滚动条和视图前面获取图像让我发疯。
这是我的一段代码:
- (void)viewDidLoad{
//scroller properties
scroller.contentSize = CGSizeMake(1300, 130);
scroller.scrollEnabled = YES;
scroller.directionalLockEnabled =YES;
scroller.frame = CGRectMake(0, 874, 768, 130);
[scroller setDelegate:self];
UIView *contentContainer = [[UIView alloc] init];
[scroller addSubview:contentContainer];
[scroller addSubview:image1];
[scroller bringSubviewToFront:image1];
[speler1 release];
UILongPressGestureRecognizer *longPress1 =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
[image1 addGestureRecognizer:longPress1];
[longPress1 release];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[image1 addGestureRecognizer:panRecognizer];
}
-(void)longPressed:(UILongPressGestureRecognizer *)sender {
[[self.view superview] bringSubviewToFront:image1];
}
-(void)move:(id)sender {
//move the image
}
我想使用 LongPressGestureRecognizer 将图像置于视图前面。 PanGestureRecognizer 负责移动图像。拖动仅在滚动视图内有效。有人知道如何将我的图像带到视图前面吗?
非常感谢帮助
Inside my UIScrollView I've got a view. Within this view there are several images. I'd like to drag the images out of my scroller (and view) to the mainview. However getting the images in front of the scroller and view is driving me bonkers.
This is a piece of my code:
- (void)viewDidLoad{
//scroller properties
scroller.contentSize = CGSizeMake(1300, 130);
scroller.scrollEnabled = YES;
scroller.directionalLockEnabled =YES;
scroller.frame = CGRectMake(0, 874, 768, 130);
[scroller setDelegate:self];
UIView *contentContainer = [[UIView alloc] init];
[scroller addSubview:contentContainer];
[scroller addSubview:image1];
[scroller bringSubviewToFront:image1];
[speler1 release];
UILongPressGestureRecognizer *longPress1 =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
[image1 addGestureRecognizer:longPress1];
[longPress1 release];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[image1 addGestureRecognizer:panRecognizer];
}
-(void)longPressed:(UILongPressGestureRecognizer *)sender {
[[self.view superview] bringSubviewToFront:image1];
}
-(void)move:(id)sender {
//move the image
}
I'd like to bring the images in front of the views by using a LongPressGestureRecognizer. The PanGestureRecognizer takes care of moving the image. The dragging works only inside the scrollview. Anyone knows how to bring my images in front of the views?
Help is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我成功地将图像从滚动条放到主视图中。请参阅下面的我的代码。
现在我希望能够将图像放回滚动视图。我正在尝试通过 Touchsend 和双击来实现这一点。图像将被放置到其原点。但是它不会返回到滚动条内部。这是一个 TouchedEnd 方法的一部分。
希望有人能指出正确的方向,以便将图像放回滚动条中原来的位置。
提前致谢!
I succeeded with putting the image from the scroller to the main view. See my code below.
Now I'd like to be able to put my images back to my scrollview. I'm trying to implement this by means of touchesended and a doubletap. The image will be placed to it's origin. However it won't go back inside the scroller. Here's a piece of the touchedended method.
Hope someone can point me in the right direction for putting the image back inside my scroller at the same location where it came from.
Thanks in advance!