簡體   English   中英

iOS 動畫塊手勢識別器

[英]iOS Animation Block Gesture Recognizer

我有一個 UICollectionView 包含許多包含視圖的單元格,這些視圖可以從集合視圖中拖出/拖放到集合視圖之外的不同視圖中。 這個過程工作正常。 但是,當拖動的視圖被放到它的新位置時,我想通過將拖動視圖縮放到其完整大小然后回到零,然后將其從超級視圖中刪除來為放置設置動畫。 當我拖動其他對象時,這適用於應用程序的其他區域,但這是唯一一個涉及集合視圖的區域。

[UIView animateWithDuration:0.375
                 animations:^{ dragView.transform = CGAffineTransformMakeScale (1.0f, 1.0f); dragView.transform = CGAffineTransformMakeScale(0.0f, 0.0f); }
                 completion:^(BOOL finished) {  [dragView removeFromSuperview]; }  ];   

如果我不使用完成塊,動畫就會失敗,大概是因為在動畫完成之前移除了視圖。 但是如果我確實使用完成塊,當動畫完成時,后續的平移手勢(用於滾動集合視圖)將傳遞給我的視圖控制器中用於其他事情的平移手勢識別器,而不是滾動集合視圖。 因此,動畫播放后,集合視圖顯示為“鎖定”。 如果我刪除完成塊,之后不會出現手勢識別問題,但動畫也不起作用。

我試過在動畫結束后在集合視圖上設置 userInteractionEnabled=YES,但它沒有幫助。

有什么建議么? TIA

天哪,你對 2 個相同類型的同步動畫有什么期望? 也許這是一個解決方案?

第一個動畫調用:

[UIView animateWithDuration:0.375
                 animations:^{ dragView.transform = CGAffineTransformMakeScale (1.0f, 1.0f); }
                 completion:^(BOOL finished) {  /*call the second animation*/ }  ];

第二個動畫調用:

//second animation
[UIView animateWithDuration:0.375
                 animations:^{ dragView.transform = CGAffineTransformMakeScale(0.0f, 0.0f); }
                 completion:^(BOOL finished) {  [dragView removeFromSuperview]; }  ]; 

在 Swift 5.0,iOS 13+ 中,將.allowUserInteraction添加到動畫選項,然后動畫不會阻止手勢識別器。

UIView.animate(
withDuration: 0.375,
delay: 0,
options: [.curveEaseOut, .allowUserInteraction],
animations: {
    dragView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
    dragView.transform = CGAffineTransform(scaleX: 0.0, y: 0.0)
},
completion: {_ in dragView.removeFromSuperview()})

暫無
暫無

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

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