LoginSignup
0
1

More than 5 years have passed since last update.

[Swift] iCarouselの中心にあるアイテムを取得する

Last updated at Posted at 2018-08-27

概要

iOSアプリのカルーセル表示でiCarouselを使用していて、カルーセルをスクロールしたときに中心のアイテムを取得したかったのでやってみました。
ちょっとこれじゃない感があるけど他に思いつかなかったので…

方法

iCarouselDelegate を継承したクラスで以下のように carouselDidEndScrollingAnimation メソッドを実装してあげます。
スクロールのアニメーションが終わったタイミングでカルーセルの中心にあるアイテムを取得しています。
コード内に記述している items はカルーセルビューのデータソースです。

ViewController.swift
    func carouselDidEndScrollingAnimation(_ carousel: iCarousel) {

        //  currentアイテムの取得
        let currentCard  = items[carousel.currentItemIndex]

    }

間違ってるとか他にもっとスマートな方法があれば教えてください…

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1