이미지 배열의 전역 변수가 있습니다.
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
})
}
}
내 이미지는 다음과 같습니다.
이 여러 가지 방법으로 할 수 있습니다
선택 -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] 삭제
몇 마디 만하겠습니다