2012-07-10 120 views
-5

我想知道如何做到這一點的效果:如何做到這一點的效果

當用戶點擊初始畫面上的加號(見第一個截圖),列表會降下來,加號更改爲負標誌(見秒截圖)。

Before http://b223.photo.store.qq.com/psb?/V11ixOec0KfVzE/fJBNAGr5NKNwTnFR7sqIfQWS5qPgVfChmOvMY1g79WY!/b/YZ1h94QZPQAAYpra9YT1PAAA

+1

圖片沒有什麼區別 – 2012-07-10 02:26:32

+1

看起來你連接的圖片被阻止了。 – dasblinkenlight 2012-07-10 02:29:42

+0

我無法查看第一張圖片;你能否把它上傳到別處? – 2012-07-10 02:30:10

回答

0

你必須寫你自己的。例如,這裏有一個超級簡單的例子,告訴你如何隱藏和顯示內容。我沒有使用圖形+/-按鈕(而是一個簡單的文本按鈕),但希望這可以爲您提供足夠的線索,讓您瞭解如何正確執行此操作。這只是演示了顯示文本面板的動畫(您可以在此面板上放置圖形或其他內容)。

有很多方法可以做到這一點,這太簡單了,顯然我沒有花時間在美學上,但希望它能向你展示一些你可以使用的技巧。我認爲關鍵的技巧就是把東西放到主視圖上的UIView上,給它一個零高度,然後動畫擴展框架的變化。您也可以移動按鈕,更改用於按鈕的UIImage等,但您明白了。

// SlideInViewController.m 

#import "SlideInViewController.h" 

@interface SlideInViewController() 
{ 
    UIView *_hiddenPanel; 
    UIButton *_hideShowButton; 
    BOOL _panelHidden; 
} 
@end 

@implementation SlideInViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // initialize the flag 

    _panelHidden = YES; 

    // create the panel that will be hidden initially (height of zero), but will be revealed when you click on the button 

    _hiddenPanel = [[UIView alloc] initWithFrame:CGRectMake(0.0, 300.0, self.view.frame.size.width, 0.0)]; 
    _hiddenPanel.clipsToBounds = YES; 
    [self.view addSubview:_hiddenPanel]; 

    // add the button 

    _hideShowButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    _hideShowButton.frame = CGRectMake(40.0, 260.0, 40.0, 40.0); 
    [_hideShowButton setTitle:@"+" forState:UIControlStateNormal]; 
    [_hideShowButton addTarget:self action:@selector(hideShowPanel:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:_hideShowButton]; 

    // now put whatever you want on this hidden panel. 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 200.0)]; 
    label.lineBreakMode = UILineBreakModeWordWrap; 
    label.numberOfLines = 0; 
    label.text = @"This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. "; 
    [_hiddenPanel addSubview:label]; 

    // Do any additional setup after loading the view. 
} 

- (IBAction)hideShowPanel:(id)sender 
{ 
    if (_panelHidden) 
    { 
     // if the panel was already hidden, let's reveal it (and move/adjust the button accordingly) 

     [UIView animateWithDuration:1.0 animations:^{ 
      _hideShowButton.frame = CGRectMake(40.0, 60.0, 40.0, 40.0); 
      [_hideShowButton setTitle:@"-" forState:UIControlStateNormal]; 

      _hiddenPanel.frame = CGRectMake(0.0, 100.0, self.view.frame.size.width, 200.0); 
     }]; 
    } 
    else 
    { 
     // if the panel was already shown, so now let's hide it again (and move/adjust the button accordingly) 
     [UIView animateWithDuration:1.0 animations:^{ 
      _hideShowButton.frame = CGRectMake(40.0, 260.0, 40.0, 40.0); 
      [_hideShowButton setTitle:@"+" forState:UIControlStateNormal]; 

      _hiddenPanel.frame = CGRectMake(0.0, 300.0, self.view.frame.size.width, 0.0); 
     }]; 
    } 

    _panelHidden = !_panelHidden; 
} 

@end 
+0

想了很多。我會試試這個。 – user1506299 2012-07-10 10:23:18

+0

@ user1506299如果有效,請告訴我! – Rob 2012-07-10 16:32:27

+1

是的,它工作得很好。非常感謝你。截圖見http://sdrv.ms/LawvBx – user1506299 2012-07-12 02:16:56

相關問題