gpt4 book ai didi

iphone- UIScrollview 对角滑动意外行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:55:00 26 4
gpt4 key购买 nike

我正在开发一个应用程序,我必须在其中从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com