2015-11-18 27 views
0

我有一个IB名为UIView ButtonHolderView。我在这个视图中添加一个UIButton和动画它。我设置了委托,这样当按下按钮时,我会通知用户。但是,动画完成后,我不能点击按钮。我可以清楚地看到该按钮位于设备和查看调试器的视图中。无法CAKeyFrameAnimation后UIButton的互动与填充模式

以下是截图:

enter image description here

和设备:

enter image description here

动画:

按钮转到左侧,然后去正确的,然后去一个,然后去正确,并停止!

代码:

ViewController.m

地产宣布:

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


-(void)viewDidAppear:(BOOL)animated{ 

    [super viewDidAppear:animated]; 

    _butTopHolder.buttonHolderViewDelegate=self; 

    [_butTopHolder addButtonViewAnimationWithCompletion:^(BOOL finished) { 

     NSLog(@"completed"); 

    }]; 

    } 

,并在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; 

} 

当使用FillMode:kCAFillModeBoth,动画后,我可以看到设备上的按钮,但不能触摸它

FillMode:kCAFillModeRemoved/Forward/Backward使用,动画后,我不能看到在装置中的按钮,但我可以在视图调试器上看到它!

我尝试设置masksToBounds为NO,但它并没有奏效。

任何人都可以给我建议的方式来解决这个问题?

回答

0

所以很傻,我不知道,如果按钮alpha是0,它不能接受任何接触!

最初,我将按钮alpha设置为0,并增加了它的alpha,一旦动画完成,按钮恢复它为0的alpha,因此它不能接收任何接触!

当我将alpha设置为1后,我可以触摸按钮!