3 回答

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
按鈕的可觸摸部分在動(dòng)畫(huà)時(shí)不會(huì)與按鈕的可見(jiàn)幀重合。
在內(nèi)部,按鈕的框架將設(shè)置為動(dòng)畫(huà)的最終值。你會(huì)發(fā)現(xiàn)你可以點(diǎn)擊這個(gè)區(qū)域,它會(huì)起作用。
要點(diǎn)擊一個(gè)移動(dòng)按鈕,你需要對(duì)按鈕的.layer.presentationLayer
屬性進(jìn)行命中測(cè)試(需要導(dǎo)入QuartzCore框架才能執(zhí)行此操作)。這通常在視圖控制器中的觸摸處理方法中完成。
如果您需要更多,我很樂(lè)意擴(kuò)展這個(gè)答案。
以下是如何通過(guò)命中測(cè)試表示層來(lái)響應(yīng)觸摸事件。此代碼位于管理按鈕的視圖控制器子類中。當(dāng)我這樣做時(shí),我對(duì)初始觸摸而不是觸摸結(jié)束感興趣(這通常是當(dāng)水龍頭會(huì)注冊(cè)時(shí)),但原理是相同的。
記得導(dǎo)入QuartzCore框架并將其添加到項(xiàng)目中。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInView:self.view]; for (UIButton *button in self.buttonsOutletCollection) { if ([button.layer.presentationLayer hitTest:touchLocation]) { // This button was hit whilst moving - do something with it here break; } }}

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
在我的情況下,我設(shè)置superView.alpha = 0
,它停止按鈕的交互,雖然我設(shè)置UIViewAnimationOptionAllowUserInteraction
。
解?容易,只需減少alpha
到0.1而不是0
[UIView animateWithDuration:durationTime delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionOverrideInheritedOptions | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations: ^{ superView.alpha = 0.1; // 0.0 will make the button unavailable to touch } completion:nil];

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
選項(xiàng)的順序是重要的,您必須先放置UIViewAnimationOptionAllowUserInteraction
,然后添加其他選項(xiàng)。
在Swift 3中使用: .allowUserInteraction
- 3 回答
- 0 關(guān)注
- 1605 瀏覽
添加回答
舉報(bào)