2012-03-29 76 views
2

我在我的UIView上動態地繪製一些按鈕。我根據一些數學計算來決定幀,並且我想在設備旋轉時重畫屏幕。我註冊了我的代碼輪換通知和didRotate:委託方法正常工作。旋轉時如何重畫屏幕? 一些更多的解釋:如果旋轉模式是肖像,我畫兩列按鈕,我想繪製四列時,旋轉到橫向..按鈕數據是動態的,來自我的HTTP服務器(按鈕數等)旋轉後重繪按鈕

+0

你繪製你的按鈕在視圖的drawRect? (如果是這樣,你可以在你的didRotate中調用setNeedsDisplay:然後檢查drawRect中的方向。) – 2012-03-29 15:46:45

+0

@PhillipMills no我畫了一個不同的方法。但我也可以在那裏畫畫,不是嗎? – ilhnctn 2012-03-29 15:49:19

回答

1

我建議您使用「willAnimateRotationToInterfaceOrientation」方法,以便在旋轉設備時控制視圖。 這是一些簡單的代碼,給你一個想法,使事情的工作:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { 

// if you are in portrait mode 
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    [yourOutletName setFrame:CGRectMake(255, 6, 25, 25)]; 
} 
// if you are in landscape mode 
else 
{ 
    [yourOutletName setFrame:CGRectMake(415, 6, 25, 25)]; 
} 
} 
+0

謝謝我試過這個,但下載數據塊,我需要高效地調用bloxk。謝謝你的回答 – ilhnctn 2012-03-29 17:23:17