ARSlideShow 1.0.0

ARSlideShow 1.0.0

Adrian Russell 维护。



ARSlideShow

为 iOS 动画图片幻灯片的库

安装

将 ARSlideShow 安装到项目中最简单的方法是使用 CocoaPods。要安装,请将以下行添加到您的 Podfile 中

pod 'ARSlideShow'

如果您希望手动安装作为依赖,请将ARSlideShow 文件夹中的所有文件复制到您的项目中。

创建幻灯片

幻灯片由 ARSlideShowController 的一个实例控制。控制器将使用要在其中展示幻灯片的容器视图实例化,并提供一个 ARSlideShowImageProviding 数据提供者,它将提供所有要显示的图像以及用于在图像之间转换的任何过渡动画器。它还可以带有一个可选的音乐控制器,可以在显示幻灯片时播放背景音乐。

简单实例

// prepare the images to be shown in the slide show.
// note that this is an example object used only by the example project and not a part of ARSlideShow
TestImagesSlideShowImagePreparation *imagePreparation = [[TestImagesSlideShowImagePreparation alloc] init];
[imagePreparation prepareImages:nil];

// create an image provider object for the slide show which will provide the images to be displayed and the transitions to use between the provided images
id<ARSlideShowImageProviding> imageProvider = [[TestSlideShowImageProvider alloc] initWithImages:imagePreparation.images];

// get the view upon which the slide show images will be displayed
UIView *containerView = self.view;

// create the slide show controller with the image provider and container view
ARSlideShowController *slideShowController = [[ARSlideShowController alloc] initWithImageProvider:imageProvider containerView:containerView musicController:nil];
slideShowController.repeat   = YES;
slideShowController.delegate = self;

// start the slide show
[slideShowController beginSlideShow];

创建图片提供者

图片提供者必须符合ARSlideShowImageProviding。共有三种方法来实现。

/**
 *  The number of images that are to be shown in the slideshow.
 */
@property (nonatomic, readonly) NSUInteger numberOfImages;


/**
 *  Returns the image to be displayed in the slide show at the specified index.
 *
 *  @param index The index of the image to return.
 *  @return The image to be displayed at the specified index.
 */
- (nonnull UIImage *)imageAtIndex:(NSUInteger)index;


/**
 *  The transition animator which should be used to transition between the specified image views.
 *  If nil is returned by this method then the slide show controller will use an instance of `NoAnimationTransitionAnimator` and no animation will occur.
 *
 *  @param index          The index of the image which is going to be displayed with the returned animation.
 *  @param existingView   The view which contains the image being currently displayed.
 *  @param presentingView The view which contains the image which is going to be displayed.
 *  @param containerView  The view where the image views are displayed and where the image will be performed.
 *
 *  @return The transition animator to be used, or nil if the default should be used.
 */
- (nullable id<ARSlideShowTransitionAnimating>)transitionAnimationForIndex:(NSUInteger)index
                                                              existingView:(nonnull UIView *)existingView
                                                            presentingView:(nonnull UIView *)presentingView
                                                             containerView:(nonnull UIView *)containerView;

创建音乐控制器

音乐控制器必须符合 ARSlideShowMusicControlling。有两种方法可以实现。

/**
 *  Start playing any music.
 */
- (void)startMusic;

/**
 *  Pause or stop playing any music.
 */
- (void)endMusic;

可用的动画过渡效果

  • 无动画 (NoAnimationTransitionAnimator)

  • 幻灯片 (SlideTransitionAnimator)

  • 弹跳 (BounceTransitionAnimator)

  • 翻转 (FlipTransitionAnimator)

  • 立方体 (CubeTransitionAnimator)

  • 淡入淡出 (FadeTransitionAnimator)

  • 虹膜渐显 (IrisTransitionAnimation)

  • 爆炸 (ExplosionTransitionAnimation)