(Swift) Slider bar changes images, but slow response

Asked 2 years ago, Updated 2 years ago, 52 views

I am creating a program that displays the image obtained by accessing http when I changed it on the slider bar in iOS program (Swift).The synchronization process makes the slide very heavy.If it is asynchronous, it will take some time for the images to come out after obtaining unnecessary images.What I want to do is to cancel the queue that was previously accumulated when I changed the slide bar and process only the last queue.List some of the asynchronous sources.If you know how to do it, please let me know.

@IBAction func slidertime (sender:UISlider) {
    let queue = dispatch_get_global_queue (DISPATCH_QUUEUE_PRIORITY_DEFAULT, 0)
    let group = dispatch_group_create()
    dispatch_group_async(group,queue,{()->Void in
        var urlstring="http://test.com/img.php?number="+String(Int(sender.value*100))
        var url = NSURL (string: urlstring)
        varerr —NSError?
        variableData:NSData=NSData(contentsOfURL:url!, options:NSDataReadingOptions.DataReadingMappedIfSafe, error:&err)!
        self.thumbnail.image=UIImage(data:imageData)
    })
}

ios swift xcode

2022-09-30 19:24

2 Answers

You only want to move the slider and process it when you're done, right?

How about doing something like that?


2022-09-30 19:24

How about getting images when touchUpInside events run instead of slider valueChanged events?


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.