alexiscreuzot / KASlideShow

Ultra-basic slideshow for iOS (ARC only).
MIT License
206 stars 61 forks source link

Auto slideshow does not work until the first manual swipe, then it works fine #44

Closed OmarAlEisa closed 6 years ago

OmarAlEisa commented 7 years ago

I'm having a difficult time trying to get the slideshow to start automatically by calling [_slideshow start] at the end of my viewDidLoad. Here's my code:

_datasource = [@[[UIImage imageNamed:@"slide1"],
              [UIImage imageNamed:@"slide2"]] mutableCopy];
_slideshow.datasource = self;
_slideshow.delegate = self;
[_slideshow setDelay:2.5]; // Delay between transitions
[_slideshow setTransitionDuration:0.5]; // Transition duration
[_slideshow setTransitionType:KASlideShowTransitionSlideHorizontal]; // Choose a transition type
[_slideshow setImagesContentMode:UIViewContentModeScaleAspectFit]; // Choose a content mode for images to display
[_slideshow addGesture:KASlideShowGestureSwipe]; // Gesture to go previous/next directly on the image
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC), 
[_slideshow start];

I'm able to fix it temporarily by placing the [_slideshow start] call in a dispatch_after block:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
      [_slideshow start];
});
glennposadas commented 7 years ago

Hi, try dispatching to main thread the slideshow start method.

yasinbor commented 7 years ago

Because your view not loaded fully when you call slideShow.start(). Just make sure your view is loaded fully when you start slide show. For this you can implement KASlideShow on viewdidload() and call start() on viewdidappear().

alexiscreuzot commented 6 years ago

closing in favour of #57