iphone- UIScrollview 对角滑动意外行为

标签 iphone objective-c ios xcode 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 builder 的 ScrollView :

@interface PuzzleViewController : UIViewController <UIScrollViewDelegate> {
    IBOutlet CustomScroll *segmentScrollview;

我已经以编程方式添加了所有 UIImageviews。

此代码按预期工作。 UIImageview 检测触摸,我可以将 UIImageview 从 UIScrollview 拖到 UIView。

但是当我对角拖动 UIImageview 时出现问题。

在我的应用程序中,当我从 ScrollView 垂直拖动 UIImageview 时,我能够将我的 UIImageView 从 UIScrollView 移动到 UIView。但是当我从 scrollview 沿对角线拖动 UIImageview 时,我无法移动 UIImageview。对角滑动滚动 UIScrollview [UIImageview 保持不变] 这是意外的。我希望 UIImageview 应该从 UIScrollview 沿对角线拖动。

如有任何帮助,我们将不胜感激。

在此先感谢您的帮助。

最佳答案

这只是一个想法...所以请尝试一下,然后告诉我进展如何。如果不起作用,那么我会尝试进一步帮助您。尝试设置 directionalLockEnabled否。如果设置为 YES,那么您的移动将仅限于水平/垂直。如果它设置为 NO 那么你应该能够沿对角线移动。试试看,让我知道结果如何。

UIScrollView directionLockEnabled Docs

If this property is NO, scrolling is permitted in both horizontal and vertical directions. If this property is YES and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction. If the drag direction is diagonal, then scrolling will not be locked and the user can drag in any direction until the drag completes. The default value is NO

关于iphone- UIScrollview 对角滑动意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7994902/

相关文章:

iphone - Xcode 本地化更新

ios - 在导航 Controller 中设置后退按钮的 Action

objective-c - Cocoa 应用程序中的自定义记录 View

iOS:添加一个连续的监听器来观察服务器上的任何变化

ios - 无法获取类 uitableview Swift 3 上的数据

ios - 在闭包中管理封装数据

iphone - UITextView 在粘贴文本时视觉上改变内容位置

objective-c - 如何在不更改 Xcode 项目的情况下 #ifdef 环境变量?

ios - 检查日历上是否存在事件

iphone - 有没有适合初学者的关于Core Graphics的好资料?