AdvancedVIEwController1.h#import <UIKit/UIKit.h>#import "AdvancedVIEw1.h"@interface AdvancedVIEwController1 : UIVIEwController {UIWindow *window;AdvancedVIEw1 *advancedVIEw1;UIImageVIEw * option1; }@property (retain) IBOutlet AdvancedVIEw1 *advancedVIEw1;@property (retain) IBOutlet UIImageVIEw *option1;@end
在IB中,我已将IBOutlet与AdvancedVIEw1链接到UIVIEw,并将选项1链接到我希望能够移动的UIImageVIEw.
AdvancedVIEwController.m#import "AdvancedVIEwController1.h"#import "AdvancedVIEw1.h"@implementation AdvancedVIEwController1@synthesize advancedVIEw1;@synthesize option1- (voID)vIEwDIDLoad { UIGestureRecognizer *pangr = [[UIPanGestureRecognizer alloc] initWithTarget:self.advancedVIEw1 action:@selector(pan:)];pangr.delegate = self;[self.advancedVIEw1 addGestureRecognizer:pangr];[pangr release]; [super vIEwDIDLoad];}AdvancedVIEw1.h#import <UIKit/UIKit.h>#import "AdvancedVIEwController1.h"@class AdvancedVIEw1;@interface AdvancedVIEw1 : UIVIEw{CGPoint* origin;}@property (nonatomic) CGPoint* origin;@endAdvancedVIEw1.m#import "AdvancedVIEw1.h"#import "AdvancedVIEwController1.h"@implementation AdvancedVIEw1;@synthesize origin;- (voID)pan:(UIPanGestureRecognizer *) gesture{if ((gesture.state == UIGestureRecognizerStateChanged) ||(gesture.state == UIGestureRecognizerStateEnded)) {CGPoint translation = [gesture translationInVIEw:self];gesture.origin = CGPointMake(gesture.origin.x+translation.x,gesture.origin.y+translation.y);[gesture setTranslation:CGPointZero inVIEw:self];}解决方法 你必须在你的pan:selector中实际设置UIVIEw的位置.而且由于您在AdvancedVIEw类中而不是在其外部执行此 *** 作,因此必须获取视图的父视图([self supervIEw]),因为更新位置是相对于父(包含)视图.试试这个:
- (voID)pan:(UIPanGestureRecognizer *)gesture{ if ((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded)) { CGPoint location = [gesture locationInVIEw:[self supervIEw]]; [self setCenter:location]; }}
请记住,您需要确保子类视图允许用户交互或手势识别器不起作用.在初始化视图时,只需使用[self setUserInteractionEnabled:YES]将其打开.
总结以上是内存溢出为你收集整理的iphone – 无法使用UIPanGestureRecognizer移动UIImageView全部内容,希望文章能够帮你解决iphone – 无法使用UIPanGestureRecognizer移动UIImageView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)