GithubHelp home page GithubHelp logo

kaslideshow's Introduction

Language CocoaPods Compatible Build Status

KASlideShow

Slideshow for iOS. Easy to use. Support manual or automatic slideshow, with fade and slide transitions. Support local and remote images.

Demo screenshot

version 3.0.0 changelog

This version introduces a lot of breaking changes. Make sure to have a look at the demo.

  • Usage is now centered around the datasource protocol.
  • Changed datasource and delegate protocols methods for more consistency
  • Introducing the long awaited remote image handling! Just put a valid image NSURL into your datasource and you're all set.

Install

Normal install

Simply copy into your project folder :

  • KASlideShow.h
  • KASlideShow.m

Using cocoapods

add this line to your Podfile : pod 'KASlideShow'

Usage

Quick example

- (void)viewDidLoad
{
    [super viewDidLoad];
    _datasource = @[[UIImage imageNamed:@"test_1.jpg"],
                    [NSURL URLWithString:@"https://i.imgur.com/7jDvjyt.jpg"],
                    @"test_3.jpg"];

    _slideshow = [[KASlideShow alloc] initWithFrame:CGRectMake(0,0,320,250)];
    _slideshow.datasource = self;
    _slideshow.delegate = self;
    [_slideshow setDelay:3]; // Delay between transitions
    [_slideshow setTransitionDuration:1]; // Transition duration
    [_slideshow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type 
    [_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display
    [_slideshow addGesture:KASlideShowGestureTap]; // Gesture to go previous/next directly on the image
}

#pragma mark - KASlideShow datasource

- (NSObject *)slideShow:(KASlideShow *)slideShow objectAtIndex:(NSUInteger)index
{
    return _datasource[index];
}

- (NSUInteger)slideShowImagesNumber:(KASlideShow *)slideShow
{
    return _datasource.count;
}

#pragma mark - KASlideShow delegate

- (void) slideShowWillShowNext:(KASlideShow *)slideShow
{
    NSLog(@"slideShowWillShowNext, index : %@",@(slideShow.currentIndex));
}

KASlideShowDataSource

You need to implement the datasource to display images. KASlideShow can handle UIImage, NNString (name of local image) and NSURL (URL of remote image).

- (NSObject *) slideShow:(KASlideShow *)slideShow objectAtIndex:(NSUInteger)index;
- (NSUInteger) slideShowImagesNumber:(KASlideShow *)slideShow;

Use of a slideshow

[_slideshow next]; // Go to the next image
[_slideshow previous]; // Got to the previous image
[_slideshow start]; // Start automatic slideshow
[_slideshow stop]; // Stop automatic slideshow

KASlideShowDelegate

- (void) slideShowDidShowNext:(KASlideShow *) slideShow;
- (void) slideShowDidShowPrevious:(KASlideShow *) slideShow;
- (void) slideShowWillShowNext:(KASlideShow *) slideShow;
- (void) slideShowWillShowPrevious:(KASlideShow *) slideShow;
- (void) slideShowDidSwipeLeft:(KASlideShow *) slideShow;
- (void) slideShowDidSwipeRight:(KASlideShow *) slideShow;

Transitions

Here are the 3 available types of transitions you can set via setTransitionType.

    KASlideShowTransitionFade
    KASlideShowTransitionSlideHorizontal
    KASlideShowTransitionSlideVertical

You can furthermore specify the transition duration via setTransitionDuration.

Gestures

Two types gestures are available to interact with the slideshow via the addGesture method. It is possible to add them both.

    KASlideShowGestureTap
    KASlideShowGestureSwipe
    KASlideShowGestureAll

kaslideshow's People

Contributors

allfake avatar babac87 avatar brandonscript avatar egold avatar jerrygdm avatar kirualex avatar kliffy avatar raztor0 avatar realbug avatar sadiq81 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kaslideshow's Issues

Auto SlideShow does not work once launch screen is executed

I am using your code as reference for my app's photo animation. The scenario should be after the launch screen was executed, the main.storyboard where in the slideShow is located, should automatically start. But unfortunately, the 1st image is the only thing that shows because the slideshow is not working. Can you help me with fix the issue? Thank you

 `import UIKit
  import KASlideShow

      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{

}
      */

@IBOutlet var whiteView: UIView!
@IBOutlet weak var slideShow: KASlideShow!

    var slideImages = [UIImage]()

override func viewDidLoad() {
    super.viewDidLoad()
    
    whiteView.layer.shadowColor = UIColor.black.cgColor
    whiteView.layer.shadowOffset = CGSize(width: 0, height: 3.0)
    whiteView.layer.shadowRadius = 3.0
    whiteView.layer.shadowOpacity = 70
  
    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.datasource = self
    slideShow.delegate = self
    
    slideShow.delay = 1
    slideShow.transitionDuration = 0.5
    slideShow.transitionType = KASlideShowTransitionType.fade
    slideShow.imagesContentMode = .scaleAspectFill
    slideShow.add(KASlideShowGestureType.all)
    
    
    if (slideImages.count > 1) {
        slideShow.start()
    }

    
    
}

override func viewDidAppear(_ animated: Bool) {
    
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


     @IBAction func eventAccessButton(_ sender: UIButton) {
          DispatchQueue.main.async {
              let OnBoardPage = self.storyboard?.instantiateViewController(withIdentifier: "OnBoardingViewController") as! OnBoardingViewController
             let appDelegate = UIApplication.shared.delegate
            appDelegate?.window??.rootViewController = OnBoardPage
        
          }
     }

    //KASlideShow delegate

   func kaSlideShowWillShowNext(slideshow: KASlideShow){
     NSLog("kaSlideShowWillShowNext")
   }

    func kaSlideShowWillShowPrevious(slideshow: KASlideShow){
     NSLog("kaSlideShowWillShowPrevious")
     }


    func kaSlideDidShowNext(slideshow: KASlideShow){
    NSLog("kaSlideDidShowNext")
    }

     func kaSlideShowDidShowPrevious(slideshow: KASlideShow){
     NSLog("kaSlideShowWillShowPrevious")
         }



         @IBAction func submitButton(_ sender: UIButton) {
             DispatchQueue.main.async {
                 let dashBoardPage = self.storyboard?.instantiateViewController(withIdentifier: "DashBoardViewController") as! DashBoardViewController
               let appDelegate = UIApplication.shared.delegate
        appDelegate?.window??.rootViewController = dashBoardPage
        
           }
    
        }
   }

`

dismissing the view controller before stopping

hi,
thanks for the library.. you literally saved me :D

I did see this issue how ever : when I dismiss the viewcontroller before stopping the slideShow it crashes. so I just added a [_slideShow stop] before dismissing the viewController,
it'd be nice if you could fix it though:)

There is no functionality to stop swipe image at last and first.

I am trying to stop left and right swipe at first and last image.

If i have 5 image array.
when i am at index 0 no right swipe, and it only display 1,2,3,4
when i am at index 4 no left swipe, and it only display 3,2,1,0

I think you understand what i am saying here.

Please help me to sort out this.

Thanks in advanced.

KASlideShow with storyboard

Demo project which u did is build on *.xib files. I need to use it with storyboard but when I run my application, all I have is black screen without pictures. Could you help me and write how to build project with your library + storyboard?

KASlideShow fails to autoslide - nil self.window blocks animation

if (!self.window) return; could return nil if view is not added in a view controller directly

self.superview might be more appropriate.

Those who are having this issue, temporarily replaceif (!self.window) return; with if (!self.superview) return; instead. Not sure if this have side effects for now.

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

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];
});

Only KASlideShowGestureSwipe some how not working - Xcode8

Only KASlideShowGestureSwipe some how not working rest is fine!!
Please advise if i'm missing some thing!!

_datasource = [@[[NSURL URLWithString:detailDic[@"image1"]],
[NSURL URLWithString:detailDic[@"image2"]]]mutableCopy];

// KASlideshow
_slideShow.datasource = self;
_slideShow.delegate = self;
[_slideShow setDelay:5]; // Delay between transitions
[_slideShow setTransitionDuration:.5]; // Transition duration
[_slideShow setTransitionType:KASlideShowTransitionSlideHorizontal]; // Choose a transition type (fade or slide)
[_slideShow setImagesContentMode:UIViewContentModeScaleAspectFill]; // 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, 4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [_slideShow start];
});

Description Issue

issue
Thanks for your great work.
On the main page under gesture heading, you typed the name of transition instead of gestures which is really confusing for anyone using this wonderful library. Please, correct description.
Regards

Add rotation support?

Just trying KASlideShow out. Nice job, but wondering if you've thought of supporting rotation? Right now the images do not resize when device orientation is changed. @naffenuf

Keep things compatible with older versions

Hello,
Is nice that you keep improving the frameworks but you should also consider to maintain compatibility with older versions.
Wasn't possible to keep the addImage method?

can't get currentIndex?

How about?

-(void)kaSlideShowDidNext:(NSInteger)index;
-(void)kaSlideShowDidPrevious:(NSInteger)index;

because I want to add a UIPageControl. :P

Video Slide

Hi,

Is it possible to include video files along with Images in KASlideShow and also I want to change delay dynamically based on Images. Please let me know how can these be done.

Images are superposed when i have two

When i have two images, they are superposed, and when i remove the block below, in "addImage" method, i get empty image in the first time :

if([self.images count] == 1){
    _topImageView.image = image;
}else if([self.images count] == 2){
    _bottomImageView.image = image;
}

KASlideShow object only starts when Images array length is greater than 1

Hi, first of all, congrats for your good work.

I've been working on a slideshow on my app with KASlideShow. However, I need to download images from a web server. The problem is that the images are download asynchronously and the slideshow won't start to animate until its images array has more than one element.

It would be great if the KASlideShow could read the addImage events live. In other words: when the download task finished the second one I shouldn't need to call the "start" method again. Take a look on my current solution:

    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [[manager imageDownloader] setMaxConcurrentDownloads:2];

    NSURL *image1 = [NSURL URLWithString:@"http://static2.businessinsider.com/image/51f03f966bb3f73c7700000b/19-fast-food-hacks-that-will-change-the-way-you-order.jpg"];
    NSURL *image2 = [NSURL URLWithString:@"http://nancyguberti.com/wp-content/uploads/2013/10/foodforlifeblog.jpg"];

    for (NSURL *url in @[image1, image2]) {
        [manager downloadWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
            [[self slideShow] addImage:image];

            if ([[[self slideShow] images] count] > 1) {
                [[self slideShow] start];
            }
        }];
    }

I appreciate your help and engagement on this amazing library.

Move to specific index

Is there a way we could jump to a specific slide index?
Like from index 0 and jump to 4 (with the slideshow set to pause of course)

Ability to perform action upon tapping on slide index

I know the library already has the Tap and Slide gesture but that is to advance the slideshow to next one.
However, Im talking about performing an action like tapping on current index and opens a URL or something. Adding this would be great!

Remove image from slideShow

In my project i have a button to delete current image. So is it possible to remove an image from slideShow ? after deleting i will show the next image with : [_slideshow next];

NSURL images aren't showing automatically

I have a horizontal scrolling image control (see code below). The first image loads very quickly. The second image also loads quickly. Typically, when I scroll to the third or fourth or fifth image, I get a blank white image and it stays blank. If I swipe left or right, and then swipe back, the image appears. The images aren't too big - 700x700px. I'm guessing the image gets downloaded fine in the background but isn't being shown when the download completes. Am I doing something wrong or is this an issue that could be investigated?

- (void)viewDidLoad 
{
    [super viewDidLoad];
    PageControl.currentPage = 0;
    PageControl.numberOfPages = 1+[add_image_list count];

    if (add_image_list != nil) {
    _datasource = [@[[NSURL URLWithString:imagelink],
                 [NSURL URLWithString:add_image_list[0]],
                 [NSURL URLWithString:add_image_list[1]],
                 [NSURL URLWithString:add_image_list[2]],
                 [NSURL URLWithString:add_image_list[3]],
                 [NSURL URLWithString:add_image_list[4]]
                 ]
               mutableCopy];
    } else {
        _datasource = [@[[NSURL URLWithString:imagelink]
                     ]
                   mutableCopy];
    }
    _slideshow.datasource = self;
    _slideshow.delegate = self;
    [_slideshow setDelay:1]; // Delay between transitions
    [_slideshow setTransitionDuration:.5]; // Transition duration
    [_slideshow setTransitionType:KASlideShowTransitionSlideHorizontal];
    [_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill];
    [_slideshow addGesture:KASlideShowGestureSwipe];
}
- (NSObject *)slideShow:(KASlideShow *)slideShow objectAtIndex:(NSUInteger)index
{
    return _datasource[index];
}

- (NSUInteger)slideShowImagesNumber:(KASlideShow *)slideShow
{
    return _datasource.count;
}
- (void) slideShowWillShowNext:(KASlideShow *)slideShow
{
    NSLog(@"slideShowWillShowNext, index : %@",@(slideShow.currentIndex));
}

- (void) slideShowDidSwipeLeft:(KASlideShow *) slideShow;
{
    [_slideshow next];
    if (PageControl.currentPage<PageControl.numberOfPages-1)
        PageControl.currentPage = PageControl.currentPage+1;
    else
        PageControl.currentPage = 0;   
}
- (void) slideShowDidSwipeRight:(KASlideShow *) slideShow;
{
    [_slideshow previous];
    if (PageControl.currentPage == 0)
        PageControl.currentPage = PageControl.numberOfPages-1;
    else
        PageControl.currentPage = PageControl.currentPage-1;
}

My original images are zooming in on slideshow

Hello All,
this works perfectly for me except one small problem, my images which are downloaded from URL, are zoomed in when they apprear in slideshow. I know i can set this property in "setImagesContentMode" but trust me i tried all of them and nothing works, sometimes it only shows half the image, it doesnt show my image 100% in the frame of slideshow. can anyone please help me here.
I have added slideshow in storyboard and this is my code in my controller
slideShow.images=[[NSMutableArray alloc]init];
slideShow.delegate = self;
[slideShow setDelay:2.0]; // Delay between transitions
[slideShow setTransitionDuration:2.0]; // Transition duration
[slideShow setTransitionType:KASlideShowTransitionSlide];
[slideShow setImagesContentMode:UIViewContentModeScaleAspectFill];
[slideShow addGesture:KASlideShowGestureAll];

the images are getting downloaded from my server and all i want is that slideshow should take my images and resize them so that it fits in the frame of slideshow
i have tried all possible combinations in setImagesContentMode.
Thanks in advance
Sachin

Dynamic loading of images in KASlideShow

The problem is that I see the photos at index 0 only after I make an initial swipe on the UIView.

  • (NSObject *)slideShow:(KASlideShow *)slideShow objectAtIndex:(NSUInteger)index {
    self.objOffer = offersAvailable[index];
    return [NSURL URLWithString:self.objOffer.imageURL];
    }

allow user to swap

If the user can swap to look the previous or next picture, it would be better.

Adding zoom to images?

We need to be able to add zoom on the images in a slideshow.

It should work similar to the Zoom function in the camera app (using double-tab or multi-touch gestures). Any ideas how this can be achieved?

This probably needs changes in the KASlideShow library?

There is no functionality to stop swipe left and right at 0 and last index.

I am trying to stop left and right swipe at first and last image.

If i have 5 image array.
when i am at index 0 no right swipe, and it only display 1,2,3,4
when i am at index 4 no left swipe, and it only display 3,2,1,0

I think you understand what i am saying here.

Please help me to sort out this.

Thanks in advanced.

Images with Transparent Background Appear in White

When using a PNG image with a transparent background, the slideshow view background turns into white. Here's a screenshot to show what actually happens (left) vs. what should happen (right).

simulator screen shot oct 24 2016 6 20 19 pm

More info:
Right now, I'm temporarily fixing this by manually changing the background color of one of the subviews of _slideshow to grey (discovered this by trial and error).

_slideshow.subviews[1].backgroundColor = [UIColor colorWithRed:232.0/255.0 green:232.0/255.0 blue:232.0/255.0 alpha:1.0];

At first I tried setting the background color to [UIColor clearColor], but the problem was that before starting the slideshow, it shows the slides staked on top of each other.

Not working with image URL

Is this working with imageURL...because in my project it gives me error and i worked with every possible methods...

[_slideshow setDelay:1]; // Delay between transitions
[_slideshow setTransitionDuration:.5]; // Transition duration
[_slideshow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type (fade or slide)
[_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display.

NSArray *imagelist = [imglist componentsSeparatedByString:@","];
NSLog(@"%@",imagelist);
[_slideshow emptyAndAddImagesFromResources:imagelist]; // Add images from resources
_slideshow.gestureRecognizers = nil;
[_slideshow addGesture:KASlideShowGestureSwipe]; // Gesture to go previous/next directly on the image
[_slideshow start];

Responsivity problems between different iPhone resolutions

I put this amazing slideshow in my app yesterday, but when it comes to test it on the iPhone 6, the images did not took all the screen width. (The Slideshow view was filling the width thanks to the constraints but the images inside took something like 3/4 of the slideshow). I tried to scale programmatically but it doesn't work. I tried this : "slideShow.contentMode = UIViewContentMode.ScaleAspectFill" but it doesn't work too.

Thanks for your attention !

caption or title

Is there a way to add caption or title on each image in slideshow ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.