我試圖在基於「視圖A」子視圖中心的UIView中繪製垂直線(稱爲視圖A)。在基於動畫CGPoint的UIView中繪製一條線。
子視圖動畫效果不錯,但是,線條畫不是動畫效果。它碰到了最後的位置。
例如,如果subview在CGPoint(0,100),我想動畫到CGPoint(100,100)。 子視圖按預期方式移動,但是,線條繪製不會僅在整個動畫中出現在CGPoint(100,100)處。
當然動畫塊內部我打電話[自setNeedsDisplay]
我使用如下所述的代碼(pointView是上面提到的子視圖):在drawRect方法
CGPointView newCetner = CGPointMake(100,100);
[UIView animateWithDuration:.5 animations:^{
pointView.center = newCenter;
[self setNeedsDisplay];
}];
我有以下代碼:
CGPathMoveToPoint(path, NULL, CGRectGetMidX(pointView.frame), pointView.center.y-100);
CGPathAddLineToPoint(path, NULL, CGRectGetMidX(pointView.frame), pointView.center.y+100);
CGContextAddPath(context, path);
CGContextStrokePath(context);
任何想法如何強制視圖根據動畫塊重繪?
你的解釋很清楚,但是當我嘗試將UIViewAnimationOptionAllowAnimatedContent傳遞給animateWithDuration時:delay:options:animations:completion:我繼續獲得相同的效果。它沒有繪製中間步驟。 – user336994
放入一個斷點並確保正在按照預期調用'drawRect:'。檢查你的「frame」和「center」值,看看它們是否按預期迭代。順便說一句,你不應該需要調用'setNeedsDisplay'。 –