Objective c UIViewAnimationOptionAllowUserInteraction不工作
问题是:我有一个类Objective c UIViewAnimationOptionAllowUserInteraction不工作,objective-c,ios,animation,Objective C,Ios,Animation,问题是:我有一个类nkcomponent,它是UIImageView的一个子类。我已经在其中实现了触摸开始/移动/结束方法,并将用户交互启用设置为打开是。但主要的问题是,当我在视图控制器中为我的nk实例设置动画时,我需要在动画过程中触摸对象。这是不可能的! nk的界面: @protocol NKIngredientDelegate <NSObject> - (void)ingredientTouched; @end @interface NKIngredient : UIIma
nkcomponent
,它是UIImageView
的一个子类。我已经在其中实现了触摸开始/移动/结束
方法,并将用户交互启用
设置为打开是
。但主要的问题是,当我在视图控制器中为我的nk
实例设置动画时,我需要在动画过程中触摸对象。这是不可能的!
nk的界面
:
@protocol NKIngredientDelegate <NSObject>
- (void)ingredientTouched;
@end
@interface NKIngredient : UIImageView {
CGPoint touchStart;
}
@property (weak, nonatomic) id <NKIngredientDelegate> delegate;
- (void)animate:(void (^)(void))animationBlock;
@end
这就是我在视图控制器中所做的:
ingredient = [[NKIngredient alloc] initWithFrame:CGRectMake(20, -50, 34, 45)];
[ingredient setImage:[UIImage imageNamed:@"liv1_Burro.png"]];
[ingredient setUserInteractionEnabled:YES];
[[self view] addSubview:ingredient];
[ingredient animate:^ (void) {
[ingredient setFrame:CGRectMake(20, 200, 34, 45)];
}];
即使在对象正在设置动画时,也能获得触摸的解决方案?因为当
nkcomponent
处于静止状态时,触摸开始/移动/结束
方法会起作用。必须按位或将标志放在一起,而不是和
UIViewAnimationOptionAllowAnimatedContent & UIViewAnimationOptionAllowUserInteraction
应该是
UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionAllowUserInteraction
否则他们会互相抵消。另外,我注意到动画触摸只在动画结束时注册…这是在哪个版本的iOS上运行的?你可以尝试UIgestureRecognitor类。我使用的是iOS 6。UIGestureRecognitor是一个很好的解决方案,但我需要移动对象。因此,用户可以拖动对象。是否可以使用UIgestureRecognitor@Ishank您可以使用
UIPangestureRecognitor
通过拖动移动视图…很好!使用UIPangestureRecognitizer可以完美地工作,但当对象正在设置动画时就不行了。有解决方案吗?好的,已更改。但情况没有改变。如果我在UIViewController类中使用touchesBegind代码,它就会工作。但我需要在UIImageView的子类NKComponent类中实现它
UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionAllowUserInteraction