This is a small app implemented on AppleWatch, developed in the language of Swift. is a guessing number of the game, the screen will appear different numbers of scrolling, and can control the beginning of the game to end, let others guess the numbers. Isn't it interesting. can also more people to play this game, than everyone who last number big. I have uploaded the app to Https://github.com/chenyufeng1991/GuessNumber.
Since this application is mostly implemented on watch, there is no effect on the phone and there is only a white interface. The implementation steps are as follows:
(1) Create a new Apple Watch app in iOS,
。
(2) Then import 3 pictures, respectively, to mark the three-in-one. The design in Interface.storyboard is as follows:
。
(3) The following are implemented in Interfacecontroller.swift:
Import Watchkitimport foundationclass Interfacecontroller:wkinterfacecontroller {@IBOutlet var image:wkinterfaceimag E! @IBOutlet var button:wkinterfacebutton! Timer; var timer:nstimer! Determine whether to start or end the Carousel; var Isstart:bool = true//picture subscript; var index:int = 1 override func Awakewithcontext (context:anyobje CT?) {Super.awakewithcontext (context)//Configure interface objects here. } override func Willactivate () {//This method was called when watch View Controller was about-to was visible to user Super.willactivate ()} override func Diddeactivate () {//This method was called when watch View Controller is no Longer visible super.diddeactivate ()} @IBAction func buttonclicked () {if (Isstart) {//start scrolling picture a Ddtimer () button.settitle ("End")}else{//stop scrolling picture self.timer.invalidate () Self.timer = nil Butto N.settitle ("Start")} Isstart =!isstart} func addtimer () {//Picture-carousel timer; self.tiMer = Nstimer.scheduledtimerwithtimeinterval (0.1, target:self, selector: "NextImage:", Userinfo:nil, Repeats:true)} Func NextImage (sender:anyobject!) {Let str = "img" + String (Index) image.setimagenamed (str) index++ if (index = = 4) {Inde x = 1}}
(4) The following results are achieved:
。
。
GitHub home: https://github.com/chenyufeng1991. Welcome everyone to visit!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
My first Apple Watch mini-game-guess number (Swift)