我有一個簡單的自定義UIView(矩形),它是用drawRect實現的。Animate自定義UIView
該視圖來自兩個值; CurrentValue的和包括maxValue
從的drawRect:
的矩形的高度表示有多少CurrentValue的是包括maxValue的:
if(currentValue > maxValue)
currentValue = maxValue;
float scale = currentValue/maxValue;
//Draw the rect
CGContextBeginPath(context);
CGContextMoveToPoint(context, self.bounds.origin.x, self.bounds.size.height);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height-(self.bounds.size.height*scale));
CGContextAddLineToPoint(context, self.bounds.origin.x, self.bounds.size.height-(self.bounds.size.height*scale));
CGContextClosePath(context);
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillPath(context);
CGContextStrokePath(context);
我設置一個視圖控制器與改變CurrentValue的和UISlider每次更改setNeedsDisplay時都會被調用。這部分工作得很好。完全按照計劃使用滑塊時,矩形會更改高度。
我的問題是..我想這高度之間的過渡是動畫。什麼是最好的方式來做到這一點?
謝謝
謝謝,我結束了使用一個簡單的UIView矩形和改變框架,而不是在UIView animateWithDuration ..然後讓控制器完成它.. – Jach0 2012-01-18 23:06:59