Iphone 如何使用手势识别Xcode拖动图像
我做了一个小测试,将UIScrollView中的视图拖动到UIView,在那里我可以调用任何操作 我正在努力使我在UIScrollView中制作的图像可以拖动。我没能做到这一点 我能够创建不是能够拖动的图像的测试视图 TestViewController.hIphone 如何使用手势识别Xcode拖动图像,iphone,objective-c,ios,xcode,drag-and-drop,Iphone,Objective C,Ios,Xcode,Drag And Drop,我做了一个小测试,将UIScrollView中的视图拖动到UIView,在那里我可以调用任何操作 我正在努力使我在UIScrollView中制作的图像可以拖动。我没能做到这一点 我能够创建不是能够拖动的图像的测试视图 TestViewController.h #import "JDDroppableView.h" @interface TestViewController : UIViewController <JDDroppableViewDelegate> { UIScroll
#import "JDDroppableView.h"
@interface TestViewController : UIViewController <JDDroppableViewDelegate>
{
UIScrollView* mScrollView;
UIView* mDropTarget;
UIImageView *images;
UIImageView *image;
CGPoint mLastPosition;
}
- (void) relayout;
- (void) addView: (id) sender;
- (void) scrollToBottomAnimated: (BOOL) animated;
@property (nonatomic, retain) IBOutlet UIImageView *images;
@property (nonatomic, retain) IBOutlet UIImageView *image;
@end
@class JDDroppableView;
@protocol JDDroppableViewDelegate <NSObject>
@optional
- (void) droppableViewBeganDragging: (JDDroppableView*) view;
- (void) droppableViewDidMove: (JDDroppableView*) view;
- (void) droppableView: (JDDroppableView*) view enteredTarget: (UIView*) target;
- (void) droppableView: (JDDroppableView*) view leftTarget: (UIView*) target;
- (BOOL) shouldAnimateDroppableViewBack: (JDDroppableView*) view wasDroppedOnTarget: (UIView*) target;
- (void) droppableViewEndedDragging: (JDDroppableView*) view;
@end
@interface JDDroppableView : UIView
{
UIView * mDropTarget;
UIView * mOuterView;
UIScrollView * mScrollView;
BOOL mIsDragging;
BOOL mIsOverTarget;
CGPoint mOriginalPosition;
}
@property (nonatomic, assign) id<JDDroppableViewDelegate> delegate;
- (id) initWithFrame:(CGRect)frame;
- (id) initWithDropTarget:(UIView*)target;
@end
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow* mWindow;
TestViewController* mViewController;
}
@end
AppDelegate.h
#import "JDDroppableView.h"
@interface TestViewController : UIViewController <JDDroppableViewDelegate>
{
UIScrollView* mScrollView;
UIView* mDropTarget;
UIImageView *images;
UIImageView *image;
CGPoint mLastPosition;
}
- (void) relayout;
- (void) addView: (id) sender;
- (void) scrollToBottomAnimated: (BOOL) animated;
@property (nonatomic, retain) IBOutlet UIImageView *images;
@property (nonatomic, retain) IBOutlet UIImageView *image;
@end
@class JDDroppableView;
@protocol JDDroppableViewDelegate <NSObject>
@optional
- (void) droppableViewBeganDragging: (JDDroppableView*) view;
- (void) droppableViewDidMove: (JDDroppableView*) view;
- (void) droppableView: (JDDroppableView*) view enteredTarget: (UIView*) target;
- (void) droppableView: (JDDroppableView*) view leftTarget: (UIView*) target;
- (BOOL) shouldAnimateDroppableViewBack: (JDDroppableView*) view wasDroppedOnTarget: (UIView*) target;
- (void) droppableViewEndedDragging: (JDDroppableView*) view;
@end
@interface JDDroppableView : UIView
{
UIView * mDropTarget;
UIView * mOuterView;
UIScrollView * mScrollView;
BOOL mIsDragging;
BOOL mIsOverTarget;
CGPoint mOriginalPosition;
}
@property (nonatomic, assign) id<JDDroppableViewDelegate> delegate;
- (id) initWithFrame:(CGRect)frame;
- (id) initWithDropTarget:(UIView*)target;
@end
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow* mWindow;
TestViewController* mViewController;
}
@end
@结束
非常感谢您的帮助
谢谢。根据苹果的
新的图像视图对象被配置为忽略用户事件
违约如果要在的自定义子类中处理事件
在UIImageView中,必须显式更改
初始化对象后,userInteractionEnabled属性设置为YES
您需要在UIImageView上将userInteractionEnabled设置为YES,如下所示:
[image setUserInteractionEnabled:YES];
希望对您有所帮助。您发布了完整的示例代码 也许你只需要问一个问题,然后参考这个项目。但是,要将其用于UIImageView,您需要分配初始化JDDroppableView并将您的imageView放在上面
UIImageView *imageView = [[UIImageView alloc] initWithImage:...];
imageView.autoresizingMask = UIAutoresizingFlexibleWidth | UIAutoresizingFlexibleHeight;
JDDroppableView *droppableView = [[JDDroppableView alloc] initWithFrame:imageView.bounds];
[droppableView addSubview:imageView];
这确实有助于我将图像放入scrollview,但如何使图像像我在那里的黑色测试视图一样拖动,当我长按视图时,它可以拖动,但不能拖动到我的图像上。谢谢