2010-01-23 69 views
1

我已經使用TableView,並通過點擊Disclosure Button使用Disclosure Button我有一個特定的圖像come.i想要當我按下Disclosure Button我必須得到特定的圖像與執行方向,所以我怎麼做it.please幫我。我在這種應用程序中是新的。如何通過按鈕的點擊事件更改方向?

回答

2

您需要手動轉換表格。這裏有一些代碼來創建和旋轉UITableView的中心。

// this defines a constant PORTRAIT_FRAME, which is the frame of the iPhone screen 
// minus the Status Bar. Equivalent to CGRectMake(0,20,320,460). 
#define PORTRAIT_FRAME [[UIScreen mainScreen] applicationFrame] 

// this defines a constant LANDSCAPE_FRAME, for orienting the table sideways 
#define LANDSCAPE_FRAME CGRectMake(0,20,480,300) 


// this function assumes you have a class variable called myTableView 
// and it toggles the orientation of myTableView 
- (void) rotateTable { 

    if (myTableView.transform == CGAffineTransformMakeRotation(0)) { 
    // rotate the image by 90 degrees 
    myTableView.transform = CGAffineTransformMakeRotation(M_PI/2); 
    myTableView.frame = LANDSCAPE_FRAME; 
    return; 
    } 

    // set the image to its original orientation 
    myTableView.transform = CGAffineTransformMakeRotation(0); 
    myTableView.frame = PORTRAIT_FRAME; 

} 

如果要觸發一個按鈕,點擊這個旋轉,然後聲明一個UIButton並指定此功能的作用。這是一個創建UIButton的函數。只需將它傳遞給@「rotateImage」以獲取目標的動作和自我。

+ (UIButton*) getButtonAtPoint:(CGPoint)point 
          target:(id)target 
          action:(NSString*)action { 

    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [button addTarget:target 
      action:NSSelectorFromString(action) 
    forControlEvents:UIControlEventTouchUpInside]; 
    return button; 
} 
+0

非常感謝您的幫助,但實際上我使用的是表格視圖,我的按鈕不是普通的按鈕,但是它是一個Disclosure Button,我該如何使用此代碼? – Viral 2010-01-23 21:30:05

+0

您可以使用與設置imageView的變換完全相同的方式來設置TableView的變換...即myTable.transform = foo。另外,Disclosure按鈕只是一種UIButton。我將編輯上面的代碼以使用該類型的按鈕。 – 2010-01-23 21:40:33

+0

好的老闆!非常感謝..... – Viral 2010-01-23 21:42:40

0

我想你可能需要使用UIApplication的setStatusBarOrientation:動畫:並旋轉/手動調整你的頂級視圖。如果你使用UIView的動畫塊方法,那麼你應該能夠在一個動畫塊中做到這一點,並承諾它獲得基本相同的效果。雖然沒有嘗試過。

+0

你能告訴我的例子,因爲我必須這樣做的按鈕點擊事件,我不知道這件事。 – Viral 2010-01-23 20:52:39