2010-09-21 52 views
0

我有一個基於視圖的應用程序,我想實現其中一個滑動菜單(我不知道是否有特定的名稱來調用它們),如Mail。ipad - 在基於視圖的應用程序上滑動菜單

想法是這樣的:我有一個板與幾個對象。當用戶點擊並按住某個對象半秒鐘時,會出現彈出窗口,顯示對象屬性。屬性有:對象顏色,對象文本,對象文本顏色和對象陰影顏色。

這4個屬性中的每一個,當點擊時,都會使新窗口從右側滑入彈出窗口,進行調整。點擊完成,視圖再次向右移動,再次顯示第一個視圖...重複所有視圖的過程。

如何將這些「滑動菜單」添加到彈出窗口中的基於視圖的應用程序?

在此先感謝

回答

1

你在說iPhone或iPad嗎?您的標籤僅適用於iPhone。

在iPad上,有一個稱爲Popover的特定UI元素。當您單擊郵件中的「回覆」圖標時,會出現一個菜單,其中顯示「回覆」和「轉發」。這是一個Popover。在iPhone上,還有另一種UI元素,例如當您要複製文本時使用。它顯示「選擇」,「剪切」等。這就是所謂的標註。請注意,您不能在iPhone上使用Popovers。

如果您在iPhone上討論Mail,您必須瞭解如何使用UINavigationController,然後使用方法-pushViewController:animated:將新頁面滑動到屏幕上。

+0

謝謝。我會尋找它。 – SpaceDog 2010-09-21 21:39:44

0

它的UINavigationController的默認動畫。所以如果你實現一個UINavigationController作爲你的UIPopoverController的根視圖,那麼推動你想要的視圖控制器,它應該是期望的效果。

+0

抱歉,沒有關於我的問題一個錯字...我有一個視圖基於應用程序。我怎麼做?你可以指向的任何代碼?謝謝。 – SpaceDog 2010-09-21 19:15:58

+0

只需谷歌爲UINavigationController並搞清楚。 – 2010-09-21 19:19:44

+0

您仍然可以將uinavigationcontroller作爲popovercontroller的根視圖。 – 2010-09-21 19:49:43

0

.H

IBOutlet UIScrollView *scrollView; 

@property (nonatomic , retain) IBOutlet UIScrollView *scrollView; 

-(void)AppleVijayAtFacebookDotCom:(id)sender; 

-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons; 

.M

@synthesize scrollView; 



-(void)AppleVijayAtFacebookDotCom:(id)sender{ 


    NSLog(@"AppleVijayAtFacebookDotCom called"); 


    UIButton *button=(UIButton *)sender; 


    if (button.tag == 0) { 

     NSLog(@"hey have clicked first button, this is my tag : %i \n\n",button.tag); 
    } 
    else if (button.tag == 1) { 

     NSLog(@"hey have clicked second button, this is my tag : %i \n\n",button.tag); 

    } 
    // ......like this 

    NSLog(@"button clicked is : %iBut \n\n",button.tag); 



}  



-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{ 

for (int i = 0; i < totalNoOfButtons; i++) { 

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [button addTarget:self action:@selector(AppleVijayAtFacebookDotCom:) forControlEvents:UIControlEventTouchUpInside]; 

     //[button1 setImage:[UIImage imageNamed:@"Button.png"] forState:UIControlStateNormal];//with image 

     //OR 

    [button setTitle:[NSString stringWithFormat:@"%iBut",i] forState:UIControlStateNormal];//with title 

    button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height); 

    button.clipsToBounds = YES; 

    button.showsTouchWhenHighlighted=YES; 

    button.layer.cornerRadius = 10;//half of the width 

    button.layer.borderColor=[UIColor redColor].CGColor; 

    button.layer.backgroundColor=[UIColor blackColor].CGColor; 

    button.layer.borderWidth=2.0f; 

    button.tag=i; 

    [self.scrollView addSubview:button]; 

} 

self.scrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height); 

    //self.navigationItem.titleView=self.scrollView;//if u have navigationcontroller then enable this line 

}

不要忘記了滾動連接在Interface Builder

,而在IB創建滾動視圖使確定你的scrollView高度是44.這是默認導航欄,所以它會看起來不錯。

in viewDidLoad call 

[self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:30]; 

輸出

enter image description here

相關問題