是否有可能創建一個UIView
子類,在Xcode使得現場(通過增加IB_DESIGNABLE
屬性作爲解釋here),但不具有自定義drawRect:
方法?直播Xcode的接口生成器UIView子類(IB_DESIGNABLE)無的drawRect:
我們有一個使用一些CAShapeLayer
S的被添加到self.layer
繪製自定義UIView
子類(因此,沒有必要重寫drawRect:
)。這個類在App上工作正常,但不會在Xcode上呈現。
如果我們複製drawRect:
中的代碼,它可以工作,但我們希望讓圖形在圖層上自動發生。
可以這樣做嗎?
我也想這樣做
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(currentContext, self.myLayer1.frame.origin.x, self.myLayer1.frame.origin.y);
[self.myLayer1 renderInContext:currentContext];
CGContextMoveToPoint(currentContext, self.myLayer1.frame.origin.x, self.myLayer1.frame.origin.y);
[self.myLayer2 renderInContext:currentContext];
}
這似乎在設備上而不是在Xcode的IB工作。
確保初始化(即設置'CAShapeLayers')代碼也從'initWithFrame:'調用。 IB呼籲進行預覽。 – rintaro 2014-09-25 15:28:06
是的,我也從那裏打電話給它。沒有運氣。你怎麼知道IB使用'initWithFrame:'?在IB預覽時有沒有調試視圖的代碼? – 2014-09-25 15:34:44
'Editor'>'從Xcode菜單中調試選定的視圖。 – rintaro 2014-09-25 15:40:30