【问题标题】:How to animate the one image button to the top of four or five buttons?如何将一个图像按钮设置为四个或五个按钮的顶部?
【发布时间】:2012-06-18 13:00:02
【问题描述】:

我是 iOS 开发中的动画新手。如何在iOS中将一个图像按钮设置为四个或五个按钮的顶部?每当我点击任何按钮时,图像按钮都必须放在该按钮的顶部。

【问题讨论】:

    标签: ios animation button imagebutton


    【解决方案1】:

    通过给予将按钮放在前面

    [self.view bringSubViewToFront:buttonName];
    

    并像这样实现动画

    CGRect basketBottomFrame = basketBottom.frame;
    basketBottomFrame.origin.y = self.view.bounds.size.height;
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    basketTop.frame = basketTopFrame;
    basketBottom.frame = basketBottomFrame;
    
    [UIView commitAnimations];
    

    【讨论】:

      【解决方案2】:

      在.h文件中,将imageButton声明为:

          int selectedCurveIndex;
          @property(nonatomic,retain)IBOutlet UIButton *mvngButton;
         -(IBAction) btnMoveTo:(id)sender;
      -(IBAction) btnDownUnder:(id)sender;
      

      在.m文件中,

      static int curveValues [] = {
      UIViewAnimationOptionCurveEaseInOut,
      UIViewAnimationOptionCurveEaseIn,
      UIViewAnimationOptionCurveEaseOut,
      UIViewAnimationOptionCurveLinear};
      
         -(IBAction) btnMoveTo:(id)sender
      {
      UIButton *btn=(UIButton *)sender;
      [mvngButton moveTo: CGPointMake(btn.center.x - (mvngButton.frame.size.width/2),btn.frame.origin.y - (mvngButton.frame.size.height + 5.0))duration:2.0 option:curveValues[selectedCurveIndex]];
      }
      -(IBAction) btnDownUnder:(id)sender
      {
      UIButton *btn=(UIButton *)sender;
      [btn downUnder:1.0 option:curveValues[selectedCurveIndex]];
      }
      

      对于剩下的四个按钮,在 xib 文件中,touchupinside 使用 -(IBAction) btnMoveTo:(id)sender 方法。 而对于 xib 文件中的 imageButton,touch up inside 方法与-(IBAction) btnDownUnder:(id)sender 方法和referencing outletmvngButton

      【讨论】:

        猜你喜欢
        • 2013-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-30
        • 2018-05-05
        • 1970-01-01
        相关资源
        最近更新 更多