2010-01-17 32 views
4

我想要一個在背面有另一個按鈕的按鈕。當你按下按鈕時,它應該水平翻轉並顯示另一個按鈕。蘋果公司在ipod-App中做了這個。當您聽到歌曲時,您可以按下導航欄右側的按鈕,然後視圖翻轉,您可以看到專輯中的所有歌曲。但是,興趣點在於右側的按鈕與水平視圖一起翻轉。 我該怎麼做?如何在背面翻轉UIButton與另一個UIButton?

alt text http://img51.imageshack.us/img51/585/welyrics2jpg.png

感謝您的回答!

回答

5

我不明白這個atm。

我的iPhone教練爲我做了一段時間回來..但我不看他做了什麼。

因此繼承了代碼。 .H

#import <UIKit/UIKit.h> 

@interface flipTesViewController : UIViewController { 
IBOutlet UIView *containerView; 

UIImageView *heads; 
UIImageView *tails; 
} 
-(IBAction)test; 

@end 

.M

#import "flipTesViewController.h" 

@implementation flipTesViewController 





-(IBAction)test{ 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(test)]; 
[UIView setAnimationDuration:.5]; 
if(heads.tag==1){ 
    [containerView addSubview:heads]; 
    heads.tag=2; 
} 
else{ 
    [containerView addSubview:tails]; 
    heads.tag=1; 
} 

[UIView commitAnimations]; 
} 



- (void)viewDidLoad { 
[super viewDidLoad]; 

heads = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NZHeads.png"]]; 
tails = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NZTails.png"]]; 

[containerView addSubview:heads]; 

} 
//other method built in to view based template 
@end 
+0

這是做到這一點的方式。 創建一個AnimationBlock並定義在其中執行的操作。 iPhone SDK知道如何處理剩餘的動畫塊,動畫塊非常強大,非常適合創建時尚動畫。 您可以使用任何東西,從添加子視圖到應用轉換。 – natanavra 2010-01-17 07:19:10

+0

如果你想獲得一些樂趣,只需註釋commitAnimations行,每個標準的iOS動畫就會變得瘋狂。反正現在首選的方法是[UIView transitionWithView:self.containerView duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^ {...} completion:nil] – 2012-11-14 21:21:14

1

在3.x中有一個簡單的方法:

  • 充分利用 「後視圖」 作爲UIViewController或它的一個子類。
  • 當按下您的 「炫」 鍵,調用

backsideViewCtrler.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:backsideViewCtrler animated:YES]; 
0
-(void)viewDidLoad 
{ 
    UIButton *btn; = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn.frame = CGRectMake(x, y, 60, 40); 
    btn.backgroundColor = [UIColor clearColor]; 
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 
    btn.tag=count; 
    [buttonWithTag setBackgroundImage:[UIImage imageNamed:@"2.png"]       forState:UIControlStateNormal]; 
    [btn setTitle:[NSString stringWithFormat:@"%d",btn.tag] forState:UIControlStateNormal]; 
    [view_frame addSubview:btn]; 
    [btn addTarget:self action:@selector(Click:)forControlEvents:UIControlEventTouchUpInside]; 
} 
    //action 
- (IBAction)Click:(id)sender 
{ 
    UIButton *click_btn = (UIButton *)sender; 
    NSLog(@"%d",click_btn.tag); 

    UIButton *buttonWithTag = (UIButton *)[view_frame viewWithTag:click_btn.tag]; 
    CATransition *animation = [CATransition animation]; 
     animation.delegate = self; 
     animation.duration = 1.0; 
     animation.timingFunction = UIViewAnimationCurveEaseInOut; 
     animation.fillMode = kCAFillModeForwards; 
     animation.removedOnCompletion = NO; 
     animation.type = @"oglFlip"; 
     [buttonWithTag.layer addAnimation:animation forKey:nil]; 
    [buttonWithTag setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal]; 
}