2009-07-17 20 views
5

İki görünüm arasında geçiş yapmaya çalışıyorum. Bu kolay, kod aşağıda, ama aynı zamanda çevirmeyi gerçekleştirmek için kullanılan düğmeyi de aynı anda çevirmek istiyorum.iPhone çevirme düğmesi (iTunes gibi)

Bir parça çalarken bu davranışını iPod uygulamasında görebilirsiniz; Kapak düğmesine dokunulduğunda kapak resmi ve parça listesi arasında geçiş yapılır, ancak düğmeyi aynı anda çevirir.

Bu, gezinme denetleyicisindeki bir sayfa ve çevirmek istediğim düğme rightBarButtonItem.

Şimdiye kadar verdiğim kod. Bu görünümü döndürür, ancak rightBarButton'u değil.

[UIView setAnimationBeginsFromCurrentState: YES]; 
[UIView setAnimationDuration: 0.5f]; 
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
showingBackside = !showingBackside; 
if (showingBackside) { 
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft 
          forView: self.view 
          cache: YES]; 
    [self.view addSubview: backside.view]; 
    [frontside.view removeFromSuperview]; 
} else { 
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight 
          forView: self.view 
          cache: YES]; 
    [self.view addSubview: frontside.view]; 
    [backside.view removeFromSuperview]; 
} 
// flip image, too 
NSString *newImage = showingBackside ? @"backside.png" : @"frontside.png"; 
[(self.navigationItem.rightBarButtonItem) setImage: [UIImage imageNamed: newImage]]; 
[UIView commitAnimations]; 

(burada görüntü çevirme kodu derlemek olmayabilir; benim yapmaya çalıştığım şeyi açıklamaya çalışmanın ardından bunu ekledi.)

Ben de belaya çalıştırıyorum olduğunu değiştirmek istiyorum Navigasyon kontrol cihazında en sağdaki buton böylece aynı anda döner.

Bunu nasıl yaparım? Hangi görüntüyü canlandırabilirim ve bunu aynı animasyon bloğunun bir parçası mı yoksa ayrı bir bölüm olarak mı yapıyorum? Herhangi bir ipucu takdir edilecektir, ben kesinlikle animasyon üzerinde iyi bir tanıtıcı yok.

cevap

5

Bazı tartışmalar var here, ancak çözüm çok zarif değil.

Her şeyden önce, UIBarButtonItem, UIView soyundan gelmiyor, muhtemelen UIKit animasyonlarını doğrudan UIBarButtonItem'dan kullanamazsınız. Ancak, bir customView ayarlamayı ve bunu hareketlendirmeyi deneyebilirsiniz. Aynı animasyon bloğunu kullanabilirsiniz.

+0

Gecenin, bunun kredi verdiğimden daha iyi bir fikir olduğunu anladım. Ben bir UIImageView görünüm yapmak ve bir düğme gibi davranmak için yeterli görüntü yakalayabildiğimi düşünüyorum, yani bunu başarabilirim. Teşekkürler. –

2

Tamam, ben aslında bu sorunu gidermek için bunu yaptık: Zaten özel bir başlık görünümünü kullanıyordum

. kullanmak yerine, özel görünümümü daha geniş yaptım.

Düğmenin her iki tarafının bir görüntüsünü, gezinti çerçevesini tamamlayarak oluşturdum ve uygulamaya yerleştirdim. Benim başlık görünümünde, ben koyun:

  • sağ kontrolü (o rightControl call) benim yedek olacak bir UIView, uygun şekilde konumlandırılmış.
  • UIControlEventTouchUpInside yanıt veren UIView üzerinde bir düğme ve flipSide: benim tetikler.

Çalışma zamanında, her durum için bir UIImageView oluşturuyorum. UIImageView s'yi rightControl numaralı telefona koyarım, ancak varsayılan olmayanı gizlerim. Gizli bayrakları, özel bir animasyon bloğunda flipSide: içinde değiştiriyorum.

Delicesine garip. Ama işe yarıyor.

+0

Bunun için bazı kodları paylaşabilir misiniz? Benzer bir şeyle uğraşmak – arnoapp

2

Sadece arasında gezinmek için iki düğme içeren sağ gezinme düğmesi için özel bir UIView kullanın.

Doğru gezinme düğmesi öğesi olarak görüntülenen özel UIView oluşturma konusunda ileriye doğru bir yaklaşım kullanabilirsiniz. Bu UIView, arasında geçiş yapmak istediğiniz iki UIButton içermelidir.UIButtonların UIViews olduğunu unutmayın, böylece normal bir UI görünümünün çevrilebileceği aynı geçişler kullanılarak çevrilebilirler ve elbette ki bunlar dokunabilir! İşte çalışan bir örnek kod:

Not: Özel bir UIViewController kategorisi olarak düğmeler oluşturmak için bir kolaylık işlevi kullanıyorum (not: UIView için de özel bir kategori oluşturmak için aynı kodu ekleyebilirsin, aynısını kopyala) UIView ile UIViewController satırlarını değiştirin ve değiştirin) - Eğer kullanmak istiyorsanız, bu kodu da ekleyerek özel bir kategori oluşturun, alternatif olarak UIButtonları normalde yaptığınız gibi oluşturabilirsiniz.

// create custom category for UIViewController to allow common button creation routine, add to .m or .mm file or add to a .h file and #import that .h file 
     @interface UIViewController (ButtonAndSelector) 
     - (UIButton *)createUIButtonWithImage:(UIImage *)image forState:(UIControlState)state withSelector:(SEL)selector usingFrame:(CGRect)buttonImageFrame; 
     @end 

     @implementation UIViewController (ButtonAndSelector) 
     - (UIButton *)createUIButtonWithImage:(UIImage *)buttonImage forState:(UIControlState)state withSelector:(SEL)selector usingFrame:(CGRect)buttonImageFrame 
     { 
      UIButton *button = [[UIButton alloc] initWithFrame:buttonImageFrame]; 
      [button setBackgroundImage:buttonImage forState:state]; 
      [button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; 
      [button setShowsTouchWhenHighlighted:YES]; 
      return button; 
     } 
     @end 

// add this to your .h file: 
     @property (strong, nonatomic) UIView *coverListView; 
     @property (strong, nonatomic) UIButton *listButton; 
     @property (strong, nonatomic) UIButton *coverButton; 

     - (void)animateCoverListButtonFlip; 

// add this to your .m or .mm file to synthesize the variables: 
     @synthesize coverListView; 
     @synthesize listButton; 
     @synthesize coverButton; 

// add this to your .m or .mm file in the viewDidLoad: 

     // setup right button bar (flips between list icon and coverart image) 
     self.coverListView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32, 30)]; 
     self.coverListView.backgroundColor = [UIColor clearColor]; 
     self.coverListView.opaque = NO; 

     self.listButton = [self createUIButtonWithImage:[UIImage imageNamed:@"navbar_icon_tracklisting"] forState:UIControlStateNormal withSelector:@selector(showHideQueue) usingFrame:CGRectMake(0, 0, 32, 30)]; 
     self.listButton.backgroundColor = [UIColor clearColor]; 
     self.listButton.showsTouchWhenHighlighted = NO; 

     self.coverButton = [self createUIButtonWithImage:[UIImage imageNamed:@"default_coverart_small"] forState:UIControlStateNormal withSelector:@selector(showHideQueue) usingFrame:CGRectMake(0, 0, 32, 30)]; 
     [self.coverListView addSubview:self.coverButton]; // show coverButton by default 
      self.coverButton.showsTouchWhenHighlighted = NO; 

     UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.coverListView]; 
     [self.navigationItem setRightBarButtonItem:barButtonItem]; 


// add this to viewDidAppear if you want to flip the button when the screen appears like the build in iPod app does 
     [self animateCoverListButtonFlip]; 

// add this routine to flip the right navigation bar custom view/buttons 
     - (void)animateCoverListButtonFlip 
     { 
      [UIView beginAnimations:nil context:NULL]; 
      [UIView setAnimationDuration:0.75];  
      [UIView setAnimationTransition:([self.listButton superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.coverListView cache:YES]; 

      if ([self.listButton superview]) { 
       [self.listButton removeFromSuperview]; 
       [self.coverListView addSubview:self.coverButton]; 
      } else { 
       [self.coverButton removeFromSuperview]; 
       [self.coverListView addSubview:self.listButton]; 
      } 
      [UIView commitAnimations]; 
     } 

// when the playing album cover changes, remember to update the coverButton: 
     UIImage *artworkImage; // set this to the current playing album image 
     [self.coverButton setImage:artworkImage forState:UIControlStateNormal]; 

// don't forget to call the animateCoverListButtonFlip in the button click handler (shown above as showHideQueue) that shows and hides the cover/queue(list of album tracks0 - something like this: 

     - (void)showHideQueue 
     {  
      [self animateCoverListButtonFlip]; 

      /* replace the code below that is commented out here with your own code that transitions between your cover view and your list view of album tracks, this code shows my transition and references views that are not part of this example/answer, but you don't need those - you'll have your own cover view (musicPlayerView) and list view (musicQueueView) to flip between. 
      [UIView beginAnimations:nil context:NULL]; 
      [UIView setAnimationDuration:0.75]; 
      [UIView setAnimationTransition:([musicQueueView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.contentView cache:YES]; 

      if ([musicQueueView superview]) { // if music queue is displayed 
       [musicQueueView removeFromSuperview]; 
       [self.contentView addSubview:musicPlayerView]; 
      } else { 
       [musicPlayerView removeFromSuperview]; 
       [self.contentView addSubview:musicQueueView]; 
       [[musicQueueView queueTableView] reloadData]; 
      } 
      [UIView commitAnimations];*/ 
     } 
İlgili konular