Note that there are some explanatory texts on larger screens.

plurals
  1. POUIViewAnimationOptionAllowUserInteraction not working
    primarykey
    data
    text
    <p>the problem is this : i have the class <code>NKIngredient</code> which is a subclass of <code>UIImageView</code>. I've implemented the <code>touchesBegan/Moved/Ended</code> methods in it and set the <code>userInteractionEnabled</code> on <code>YES</code>. But the major problem is that when i animate my <code>NKIngredient</code> instance in a view controller i need the object can be touched during the animation. And this is impossible! The interface of <code>NKIngredient</code> : </p> <pre><code>@protocol NKIngredientDelegate &lt;NSObject&gt; - (void)ingredientTouched; @end @interface NKIngredient : UIImageView { CGPoint touchStart; } @property (weak, nonatomic) id &lt;NKIngredientDelegate&gt; delegate; - (void)animate:(void (^)(void))animationBlock; @end </code></pre> <p>The implementation file : </p> <pre><code>@implementation NKIngredient - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setUserInteractionEnabled:YES]; } return self; } //Viene chiamato questo metodo se l'oggetto è disegnato come nib - (id)initWithCoder:(NSCoder *)aDecoder { NSLog(@"NKIngredient initWithCoder"); if (self = [super initWithCoder:aDecoder]) { [self setUserInteractionEnabled:YES]; } return self; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ - (BOOL)becomeFirstResponder { return YES; } - (void)animate:(void (^)(void))animationBlock { [UIView animateWithDuration:8.0 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent &amp; UIViewAnimationOptionAllowUserInteraction animations:animationBlock completion:^ (BOOL finished) { NSLog(@"Completed"); }]; } #pragma mark - Touch interaction - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //NSLog(@"Touches began"); [_delegate ingredientTouched]; touchStart = [[touches anyObject] locationInView:self]; NSLog(@"Touched"); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"Touches moved"); CGPoint point = [[touches anyObject] locationInView:self]; self.center = CGPointMake(self.center.x + point.x - touchStart.x, self.center.y + point.y - touchStart.y); } @end </code></pre> <p>And this is what i do in my view controller : </p> <pre><code>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)]; }]; </code></pre> <p>Some solution to get the touch even when the object is animating? Because when the <code>NKIngredient</code> is stationary the <code>touchesBegan/Moved/Ended</code> methods works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload