簡體   English   中英

CAAnimation - 禁用用戶輸入

[英]CAAnimation - User Input Disabled

我正在嘗試為按鈕設置動畫。 當我這樣做時(使用button.layer addAnimation),該按鈕將被禁用。 動畫時有沒有辦法讓用戶互動? 我還嘗試使用傳遞UIViewAnimationOptionAllowUserInteraction選項的animateWithDuration包裝塊中的所有內容,但它仍然不起作用。

編輯:這很奇怪。 如果我點擊上角(我放置按鈕的位置),它會觸發事件。 這幾乎就像按鈕的框架不跟隨動畫。

編輯:我最終做的是創建一個事件,每0.1秒觸發一次,將button.frame設置為等於[[button.layer presentationLayer]框架]。 這似乎成功了。

最佳解決方案是在調用動畫后更改圖層的位置:

[button.layer addAnimation:animation forKey:@"animation"];

 button.layer.position = endPosition;

在UIViewAnimationOptions參數中使用以下UIView方法和UIViewAnimationOptionAllowUserInteraction:

+(void)animateWithDuration:(NSTimeInterval)持續時間延遲:(NSTimeInterval)延遲選項:(UIViewAnimationOptions)選項動畫:(void(^)(void))動畫完成:(void(^)(BOOL完成))完成

對我而言,射擊事件似乎有些過時了
但是你提到的[[button.layer presentationLayer] frame]讓我走上正軌:-)

因此,通過將手勢識別器附加到移動視圖的超級視圖,我可以執行以下檢測:

CGPoint tapLocation = [gestureRecognizer locationInView:self.view];

for (UIView* childView in self.view.subviews)
{
    CGRect frame = [[childView.layer presentationLayer] frame];
    if (CGRectContainsPoint(frame, tapLocation))
    {
        ....
    }
}

我想讓按鈕放大。所以我在開始動畫之前縮小圖層:

layer.transform = CATransform3DScale (layer.transform, 0.01, 0.01, 0.01);

// some animation code

在動畫之后我將它縮放回來。

// some animation code
CATransform3D endingScale = CATransform3DScale (layer.transform, 100, 100, 100);
// some animation code

[layer addAnimation:animation forKey:@"transform"];

layer.transform = endingScale;

看起來如果您直接將其分配給圖層,框架將會更改。 但是,使用動畫不會更改框架。

我最終做的是創建一個每0.1秒觸發一次的事件,將button.frame設置為等於button.layer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM