8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【WatchKit】How to make an animated background Interface in Apple WatchKit(Watchkitで背景画像をアニメーションさせる方法)

Last updated at Posted at 2015-04-09

##デモ
jacksonnn-compressor.gif

##実現方法
Watchkitで背景画像をアニメーションさせる方法
まずWatchKitではSubview的にinterfaceを重ねられません。
どうするかというと、WKInterfaceGroupを利用します。

WKInterfaceGroupのsetBackgroundImageメソッドにて画像を割り当てて、
その画像でUIImage型の配列を指定(animatedImageWithImages)にてアニメーションが可能となります。

##ソース



https://gist.github.com/0ba3d3f4b0b0b2e2bd08.js

File: InterfaceController.swift
-------------------------

     @IBOutlet weak var bg: WKInterfaceGroup!

    override func awakeWithContext(context: AnyObject?) {
        var images: [UIImage] = []
        
        for (var i=1; i<71; i++){
            images.append(UIImage(named:String(format:"jackson%d.jpg", i))!)
        }

        let animatedImage = UIImage.animatedImageWithImages(
            images,
            duration: 5)
        
        self.bg.setBackgroundImage(animatedImage)
        self.bg.startAnimatingWithImagesInRange(
                    NSRange(location: 0, length: 70),
                    duration: 5,
                    repeatCount: 0)
    }

use with Gist Search

8
8
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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?