Reputation: 241
I tried self.heartSymbol.setImage(currentBeatPattern.heartImage)
in the newBeat() function but no heartImages are loading. What should I do there?
A single image loads fine if I use something like self.heartSymbol.setImage(UIImage(named:"greenHeartNormal"))
but as you can see from my array and my newBeat() function I'm trying to load images via an array and out to an IBOutlet.
The idea is that each image is supposed to appear on the screen and pulse for a few seconds each and a bpmLabel also changes value along with it. The animations don't work in WatchKit so I've commented out that beat() function for now. But I'd still like to do this with static images from the array and that bpmLabel. Using the commented out beat() function how can I edit it so that I get my time-delayed bmpLabel text output without the pulsing iconLabel transform animations?
import WatchKit
import Foundation
struct BeatPattern {
var heartImage = WKInterfaceImage()
var description = "Normal"
var bpm = 80
var duration: Double {
return 60.0 / Double(bpm)
}
}
let redHeartFast = WKInterfaceImage()
let yellowHeartElevated = WKInterfaceImage()
var greenHeartNormal = WKInterfaceImage()
let purpleHeartSlow = WKInterfaceImage()
let blueHeartSedated = WKInterfaceImage()
class InterfaceController: WKInterfaceController {
@IBOutlet weak var heartSymbol2: WKInterfaceImage!
@IBOutlet weak var heartSymbol: WKInterfaceImage!
@IBOutlet weak var bpmLabel: WKInterfaceLabel!
var currentBeatPattern = BeatPattern()
var currentBeatPatternIndex = 0
var beatPatternsArray = [
BeatPattern(heartImage: redHeartFast, description: "Fast", bpm: 180),
BeatPattern(heartImage: yellowHeartElevated, description: "Elevated", bpm: 140),
BeatPattern(heartImage: greenHeartNormal, description: "Normal", bpm: 80),
BeatPattern(heartImage: purpleHeartSlow, description: "Slow", bpm: 55),
BeatPattern(heartImage: blueHeartSedated, description: "Sedated", bpm: 30)]
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
//self.heartSymbol.setImage(UIImage(named:"greenHeartNormal")) // new code
}
override func willActivate() {
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
newBeat()
NSTimer.scheduledTimerWithTimeInterval(8,
target: self,
selector: Selector("newBeat"),
userInfo: nil,
repeats: true)
//beat()
}
func newBeat() {
if ++currentBeatPatternIndex == beatPatternsArray.count {
currentBeatPatternIndex = 0
}
currentBeatPattern = beatPatternsArray[currentBeatPatternIndex]
heartSymbol = currentBeatPattern.heartImage ////// ERROR
}
/*
func beat() {
// 1
UIView.animateWithDuration(currentBeatPattern.duration / 2,
delay: 0.0,
options: .CurveEaseInOut,
animations: {
// 2
self.iconLabel.transform = CGAffineTransformScale(self.iconLabel.transform, self.shrinkFactor, self.shrinkFactor)
},
completion: { _ in
// 3
UIView.animateWithDuration(self.currentBeatPattern.duration / 2,
delay: 0.0,
options: .CurveEaseInOut,
animations: {
// 4
self.iconLabel.transform = CGAffineTransformScale(self.iconLabel.transform, self.expandFactor, self.expandFactor)
},
completion: { _ in
// 5
self.beat()
}
)
}
)
}
*/
Upvotes: 0
Views: 419
Reputation: 7260
For animations based on image resource files, name the image files using the convention name+number.extension
, where the name and extension strings are the same for all images and the number value indicates the position of the image in the animation sequence. The number of the first image in the sequence must be 0 or 1. For example, an animation with three images could have the file names image1.png, image2.png, and image3.png.
It is recommended that you place image resource files in the bundle of your WatchKit app (not in your WatchKit extension’s bundle). Placing them in the WatchKit app bundle lets you use the setImageNamed:
method of this class to specify the animated image. You can start animation with startAnimatingWithImagesInRange:duration:repeatCount:
method. Or create an animated image with [UIImage animatedImageNamed:duration:]
then set it.
Upvotes: 1