我正在开发一个应用程序,我必须从UIScrollview拖动UIImageview。 在我的主UIView的底部,我有一个UIScrollView和UIImageViews里面。 我一直在使用下面的代码中创建自定义的UIScrollView:iphone- 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;
}
I已经以编程方式添加了所有UIImageviews。
此代码按预期工作。 UIImageview检测触摸,我可以将UIImageview从UIScrollview拖到UIView。
但是,当我对角拖动UIImageview时会出现问题。
在我的应用程序,当我从scrollview垂直拖动UIImageview我能够将我的UIImageView从UIScrollView移动到UIView。但是当我从scrollview对角地拖动UIImageview时,我无法移动UIImageView。对角滑动滚动UIScrollview [UIImageview保持不变]这是意想不到的。我想UIImageView应该从UIScrollview对角线拖动。
任何帮助将不胜感激。
在此先感谢您的帮助。
谢谢山姆和PTBG的回复。但是,directionalLockEnabled不起作用。问题依然存在。我无法从scrollview中对角地拖动UIImageView。 – user392406