0

I have a UIView named ButtonHolderView in IB. I added a UIButton in this view and animated it. I set the delegate, so that when the button is pressed, I notify the user. However, after the animation is done, I cant click on the button. I can clearly see that button is on the view in both device and on view debuggger.

Here are the screenshots:

enter image description here

and on device:

enter image description here

Animation:

THe button goes to the left, and then goes to the right, and then goes to left a, and then goes to right, and stop!!!!

Code:

ViewController.m

Property declared:

  @property (nonatomic,strong) IBOutlet ButtonHolderView *butTopHolder;


-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
   
    _butTopHolder.buttonHolderViewDelegate=self;
    
    [_butTopHolder addButtonViewAnimationWithCompletion:^(BOOL finished) {
       
        NSLog(@"completed");
        
    }];

  }

and in the ButtonHolderView.m:

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setupHierarchy];
    }
    return self;
}



- (void)setupHierarchy
{
    
    UIView *scaling = [UIView new];
    scaling.clipsToBounds=NO; //tried to set NO
    scaling.bounds = CGRectMake(0, 0, 320, 568);
    scaling.center = CGPointMake(320.0, 568.0);
    scaling.layer.masksToBounds = NO; //tried to set NO
    [self addSubview:scaling];
    
    UIButton *aboutme = [UIButton buttonWithType:UIButtonTypeCustom];
    aboutme.userInteractionEnabled=YES;
    aboutme.bounds = CGRectMake(0, 0, 50.0, 50.0);
    UIImage *imgAboutme = [UIImage imageWithContentsOfFile:[bundle pathForResource:@"aboutme.png" ofType:nil]];
    [aboutme setBackgroundImage:imgAboutme forState:UIControlStateNormal];
    aboutme.contentMode = UIViewContentModeCenter;
    aboutme.layer.position = CGPointMake(80, 80);
    aboutme.alpha = 0.00;
    [aboutme addTarget:self action:@selector(actionAboutmePressed:) forControlEvents:UIControlEventTouchUpInside];
    [scaling addSubview:aboutme];
  }


- (void)addButtonViewAnimationWithCompletion:(void (^)(BOOL finished))completionBlock
{
    [self addButtonViewAnimationWithBeginTime:0 andFillMode:kCAFillModeBoth andRemoveOnCompletion:NO completion:completionBlock];
}



- (void)addButtonViewAnimationWithBeginTime:(CFTimeInterval)beginTime andFillMode:(NSString *)fillMode andRemoveOnCompletion:(BOOL)removedOnCompletion completion:(void (^)(BOOL finished))completionBlock
{
    CAMediaTimingFunction *linearTiming = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    CAKeyframeAnimation *aboutmeTranslationXAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
aboutmeTranslationXAnimation.duration = 1.150;
aboutmeTranslationXAnimation.values = @[@(0.000), @(-130.000), @(100.000), @(-20.000), @(70.000), @(0.000)];
aboutmeTranslationXAnimation.keyTimes = @[@(0.000), @(0.261), @(0.435), @(0.609), @(0.783), @(1.000)];
aboutmeTranslationXAnimation.timingFunctions = @[linearTiming, linearTiming, linearTiming, linearTiming, linearTiming];
aboutmeTranslationXAnimation.beginTime = beginTime;
aboutmeTranslationXAnimation.fillMode = fillMode;
aboutmeTranslationXAnimation.removedOnCompletion = removedOnCompletion;

}

When the FillMode:kCAFillModeBoth is used, After animation,I can see the button on the device, but cant touch it

When the FillMode:kCAFillModeRemoved/Forward/Backward is used,After animation, I cant see the button on device,but I can see it on view debugger!!!

I tried setting the masksToBounds to NO but it didnt worked.

Can anyone suggest me a way to fix this?

Community
  • 1
  • 1
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109

1 Answers1

0

So Silly, I don't know that if button alpha is 0, it can't receive any touches!!!!

Initially I set the button alpha to 0 and increased its alpha, once the animations are done, the button restores it alpha which is 0, hence it can't receive any touches!!!

After I made alpha to 1, I am able to touch the button!!!

Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109