我试图使用KASlideshow窗格在幻灯片放映中使用淡入淡出动画,但是图像未显示在输出中。我试图用我在stackoverflow中看到的解决方案来解决它,但对我不起作用。the solution I tried but did not work
这是我的代码供您参考。请帮助我解决它。谢谢
ViewController类
class ViewController: UIViewController, KASlideShowDelegate, KASlideShowDataSource {
func slideShow(_ slideShow: KASlideShow!, objectAt index: UInt) -> NSObject! {
return slideImages[0];
}
func slideShowImagesNumber(_ slideShow: KASlideShow!) -> UInt {
return UInt(slideImages.count)
}
func slideShow(slideShow: KASlideShow, imageForPosition position: KASlideShowPosition) -> UIImage{
//missing code here
}
声明
@IBOutlet var whiteView: UIView!
@IBOutlet weak var slideShow: KASlideShow!
var slideImages = [UIImage]()
viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
slideImages = [
UIImage(named: "img1.png"),
UIImage(named: "img3.png"),
UIImage(named: "img5.png"),
UIImage(named: "img6.png"),
UIImage(named: "img8.png"),
UIImage(named: "img9.png"),
UIImage(named: "img11.png"),
UIImage(named: "img12.png"),
UIImage(named: "img13.png"),
UIImage(named: "img14.png"),
UIImage(named: "img15.png"),
UIImage(named: "img16.png"),
UIImage(named: "img17.png"),
UIImage(named: "img18.png"),
UIImage(named: "img19.png"),
UIImage(named: "img21.png"),
UIImage(named: "img22.png"),
UIImage(named: "img23.png"),
] as! [UIImage]
slideShow.delegate = self
slideShow.datasource = self
slideShow.delay = 1
slideShow.transitionDuration = 0.5
slideShow.transitionType = KASlideShowTransitionType.fade
slideShow.imagesContentMode = .scaleAspectFill
slideShow.add(KASlideShowGestureType.tap)
slideShow.start()
KASlideShow委托
func kaSlideShowWillShowNext(slideshow: KASlideShow){
NSLog("kaSlideShowWillShowNext")
}
/*func kaSlideShowWillShowPrevious(slideshow: KASlideShow){
NSLog("kaSlideShowWillShowPrevious")
}
func kaSlideDidShowNext(slideshow: KASlideShow){
NSLog("kaSlideDidShowNext")
}
func kaSlideShowDidShowPrevious(slideshow: KASlideShow){
NSLog("kaSlideShowWillShowPrevious")
}
*/
答案 0 :(得分:0)
you need to change datasource method and images array set only name like this
arrslideImages = ["test_1.jpeg","test_2.jpeg","test_3.jpeg"]
func slideShow(_ slideShow: KASlideShow!, objectAt index: UInt) -> NSObject! {
let ind = NSInteger(index)
return slideImages[ind] as NSObject;
}