淡入淡出,使图像阵列快速移动

appiconhero.co

我有一个图像数组的全局变量

public var images = ["11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18"]

我想显示它在单击按钮2秒后淡入淡出每个图像。表示当图像“ 11”首先出现时,在2秒钟后,它会淡出,然后图像“ 12”会淡入,依此类推。但是我的代码运行不正常。

这是我的代码:

@IBAction func playAutomaticPhotoImages(sender: AnyObject) {

    for image in images {
      photoImageView.hidden = false
      photoImageView.alpha = 1.0
      UIView.animateWithDuration(2.0, animations: {
        self.photoImageView.image = UIImage(named: image)
        self.photoImageView.alpha = 1
        }, completion: {
          (value: Bool) in
          self.photoImageView.hidden = true
          self.photoImageView.alpha = 0.0
      })
    }
  }

这是我的形象:

在此处输入图片说明

安布·卡尔提克(Anbu.Karthik)

您可以通过多种方式执行此操作

选择-1

@IBAction func playAutomaticPhotoImages(sender: AnyObject) {

 self.animateImages()

 }

fun animateImages()
{
  var count: Int = 0

  var images = ["11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18"]

var image: UIImage = images[(count % images.count)]

UIView.transitionWithView(self.photoImageView, duration: 2.0, options: .CurveEaseOut, animations: {() -> Void in
self.photoImageView.image = image
}, completion: {(finished: Bool) -> Void in
self.animateImages()
// once finished, repeat again
count++
})

 }

选择2

 @IBAction func playAutomaticPhotoImages(sender: AnyObject) {

 self.animateImages(0) /*call animageImage with parameter number as image number as i user image name as "11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18", "11", "12", "13", "14", "15", "16", "17", "18"*/

 }



    func animateImages(no:Int)
    {
        var Number:Int = no
        let t:NSTimeInterval = 1;
        let t1:NSTimeInterval = 0;
        var name:String = "yourImageName\(Number).png"
        self.photoImageView!.alpha = 0.4
        self.photoImageView!.image = UIImage(named:name);

        //code to animate bg with delay 2 and after completion it recursively calling animateImage method 
        UIView.animateWithDuration(2.0, delay: 0, options:UIViewAnimationOptions.CurveEaseOut, animations: {() in 
                                                       self.photoImageView!.alpha = 1.0;
                                                   }, 
                                         completion: {(Bool) in
                                                      Number++;

                                                      self. animateImages(Number); 
                                                   })
    }
}

选择3

@IBAction func playAutomaticPhotoImages(sender: AnyObject) {

NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: "crossfade", userInfo: nil, repeats: true)


photoImageView.animationImages = images

photoImageView.animationDuration = 2
photoImageView.animationRepeatCount = 0        
photoImageView.startAnimating()


 }




func crossfade() {
UIView.animateWithDuration(2.0, delay: 0.0, options: .CurveEaseInOut, animations: {() -> Void in
    photoImageView.alpha = !photoImageView.alpha
}, completion: {(done: Bool) -> Void in
    //
})
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章