iphone- UIScrollview 对角线滑动意外行为
我正在开发一个应用程序,其中我必须从 UIScrollview 中拖动 UIImageview 。 在我的主 UIView 的底部,我有一个 UIScrollView,里面有 UIImageViews。 我使用以下代码片段创建了自定义 UIScrollview:
@interface CustomScroll : UIScrollView {
}@end
@implementation CustomScroll
- (id)initWithFrame:(CGRect)frame {
return [super initWithFrame:frame];
}
- (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event {
// If not dragging, send event to next responder
if (!self.dragging) {
self.scrollEnabled=NO;
[self.nextResponder touchesMoved:touches withEvent:event];
}
else{
[super touchesMoved: touches withEvent: event];
}
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
// If not dragging, send event to next responder
if (!self.dragging)
[self.nextResponder touchesEnded: touches withEvent:event];
else
[super touchesEnded: touches withEvent: event];
}
@end
从这里开始,我在 PuzzleViewController 中包含了一个 CustomScroll 对象,并将其连接到界面生成器的滚动视图:
@interface PuzzleViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet CustomScroll *segmentScrollview;
}
我以编程方式添加了所有 UIImageview。
该代码按预期工作。 UIImageview 检测触摸,我可以将 UIImageview 从 UIScrollview 拖动到 UIView。
但是当我对角拖动 UIImageview 时会出现问题。
在我的应用程序中,当我从滚动视图垂直拖动 UIImageview 时,我可以将 UIImageView 从 UIScrollView 移动到 UIView。但是当我从滚动视图对角拖动 UIImageview 时,我无法移动 UIImageview。对角滑动滚动 UIScrollview [UIImageview 保持不变],这是意外的。我希望 UIImageview 应该从 UIScrollview 对角拖动。
任何帮助将不胜感激。
预先感谢您的任何帮助。
I am developing an app in which I have to drag UIImageview from UIScrollview.
At the bottom part of my main UIView, I've an UIScrollView with UIImageViews inside.
I have created custom UIScrollview using following code snippet:
@interface CustomScroll : UIScrollView {
}@end
@implementation CustomScroll
- (id)initWithFrame:(CGRect)frame {
return [super initWithFrame:frame];
}
- (void) touchesMoved: (NSSet *) touches withEvent: (UIEvent *) event {
// If not dragging, send event to next responder
if (!self.dragging) {
self.scrollEnabled=NO;
[self.nextResponder touchesMoved:touches withEvent:event];
}
else{
[super touchesMoved: touches withEvent: event];
}
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
// If not dragging, send event to next responder
if (!self.dragging)
[self.nextResponder touchesEnded: touches withEvent:event];
else
[super touchesEnded: touches withEvent: event];
}
@end
From here I have included a CustomScroll object in my PuzzleViewController and connect it to the scrollview of Interface builder:
@interface PuzzleViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet CustomScroll *segmentScrollview;
}
I've added all UIImageviews programmatically.
This code is working as expected. UIImageview detecting touch and I can drag UIImageview from UIScrollview to UIView.
But problem occurs when I drag UIImageview diagonally.
In my app when I drag UIImageview vertically from scrollview I'm able to move my UIImageView from the UIScrollView to the UIView. But when I drag UIImageview diagonally from scrollview I can not move UIImageview. Diagonal swipe scrolls UIScrollview [UIImageview remains untouched] which is unexpected. I want UIImageview should be drag diagonally from UIScrollview.
Any help would be greatly appreciated.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这只是一个想法……所以尝试一下并告诉我效果如何。如果不起作用,那么我会尽力进一步帮助您。尝试设置
DirectionLockEnabled
为 NO。如果设置为“是”,那么您的移动将仅限于水平/垂直。如果它设置为“否”,那么您应该能够沿对角线移动。尝试一下并让我知道效果如何。UIScrollView DirectionLockEnabled 文档
This is just a thought...so try it out and tell me how it goes. If doesn't work then I'll try and help you out further. Try setting
directionalLockEnabled
to NO. If it is set to YES then your movement will be restricted to horizontal/vertical only. If it is set to NO then you should be able to move diagonally. Try it out and let me know how it goes.UIScrollView directionLockEnabled Docs
我认为你所追求的不是 [super TouchesMoved:...],而是 [self.superview TouchsMoved:...] ...假设你有包含 CustomScroll 和你所在的其他视图的超级视图试图拖入设置来处理这个问题。
i am thinking that what you are after is not [super touchesMoved:...], but rather [self.superview touchesMoved:...] ... assuming you have the superview containing both the CustomScroll and the other view that you are attempting to drag into set up to deal with this.
我知道这是一个较旧的问题,但我也遇到了这个问题。基本上我想要一个启用分页的滚动视图,它可以向上、向下、向左或向右移动。使用 pagingEnabled 和 orientationLockEnabled 变量使其基本上可以工作,除了对角线拖动之外。我的解决方案如下。
这会强制任何对角线滑动将滚动锁定在水平面上,这对我来说效果很好,因为水平拖动是优先级,所以向上或向下滚动的唯一方法是精确向上或向下滑动。
为此,您需要声明
并
} SW_SCROLL_DIRECTION;
笔记。这可能无法开箱即用,正如您所看到的,我硬编码了 3 页的值。这是因为我的内容始终居中,因此您可以向任何方向滚动一页,然后它会以动画方式返回到中心。修改以处理多个页面应该不难。
I know this is an older question, but I just ran into this problem as well. Basically I wanted a paging enabled scrollview which would go either up, down, left, or right. Using the pagingEnabled and directionalLockEnabled variables made it basically work, except for the diagonal drag. My solution is below.
This forces any diagonal swipes to lock the scrolling on the horizontal plane, which worked well for me because horizontal dragging was a priority, so The only way to scroll up or down would be to swipe exactly up or down.
For this to work you will need to declare
and
} SW_SCROLL_DIRECTION;
Note. This probably wont work out of the box, as you see I hardcode a value of 3 pages. This is because I have content always centred, so you can either scroll one page in any direction, then it will animate back to the centre. It shouldn't be to hard to modify to work with multiple pages.