时间:2017年05月22日星期一
说明:本文部分内容均来自慕课网。@慕课网:http://www.imooc.com
教学示例源码:https://github.com/zccodere/s...
个人学习源码:https://github.com/zccodere/s...

第一章:课程简介&Xcode下载

1-1 课程简介

制作一个猜拳游戏APP,剪刀、石头、布。

效果图如下:

图片描述

1-2 Xcode的下载

使用AppStore下载并安装Xcode

Apple Watch分类

WatchKit Apps:可以跟iphone手机进行交互的app
Glances:呈现一些简单的信息,点击时,一般会进入WatchKit Apps
Actionable Notifications:通知消息

第二章:界面制作

2-1 通过Storyboard制作界面

watch与iphone的关系

clipboard.png

项目界面原型

clipboard.png

第三章:编写程序逻辑

3-1 通过与InterfaceController连接来编写程序逻辑

代码演示:

//
//  InterfaceController.swift
//  MyConflictResolver Watch App Extension
//
//  Created by zc on 2017/5/22.
//  Copyright © 2017年 com.zccoder. All rights reserved.
//

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {

    @IBOutlet var actionImage: WKInterfaceImage!
    
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        
        // Configure interface objects here.
    }
    
    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }
    
    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }
    
    @IBAction func playTappad() {
        // 随机生成0-2之间的整数
        let imageName = arc4random_uniform(3)
        self.actionImage.setImageNamed("action\(imageName)")     
    }
}

第四章:制作动画效果

4-1 在Watch App里面制作动画效果

代码演示:

//
//  InterfaceController.swift
//  MyConflictResolver Watch App Extension
//
//  Created by zc on 2017/5/22.
//  Copyright © 2017年 com.zccoder. All rights reserved.
//

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {

    @IBOutlet var actionImage: WKInterfaceImage!
    
    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        
        // Configure interface objects here.
    }
    
    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }
    
    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }
    
    @IBAction func playTappad() {
        // 动画效果
        actionImage.setImageNamed("action")
        actionImage.startAnimatingWithImages(in: NSRange(location: 0,length: 3), duration: 0.4, repeatCount: 5)
        
        // 等待0.9秒后执行
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.9) {
            // 随机生成0-2之间的整数
            let imageName = arc4random_uniform(3)
            self.actionImage.setImageNamed("action\(imageName)")
        }
    }
}

妙手空空
1.3k 声望370 粉丝

博观而约取,厚积而薄发