Skip to content

Commit 0464f55

Browse files
committed
Merge pull request MengTo#20 from 0oneo-work/master
some fix
2 parents bdfefde + d1ba12b commit 0464f55

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

Spring/Misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
157157
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
158158
let now = NSDate()
159159
let earliest = now.earlierDate(date)
160-
let latest = (earliest == now) ? date : now
160+
let latest = now.laterDate(date)
161161
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
162162

163163
if (components.year >= 2) {

SpringApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@
245245
1A4FDA431A6E44780099D309 /* SpringTests */,
246246
9641173C1A5BE90A000E3A5A /* Products */,
247247
);
248+
indentWidth = 4;
248249
sourceTree = "<group>";
250+
tabWidth = 4;
249251
};
250252
9641173C1A5BE90A000E3A5A /* Products */ = {
251253
isa = PBXGroup;

SpringApp/SpringViewController.swift

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,38 +166,18 @@ class SpringViewController: UIViewController, UIPickerViewDelegate, UIPickerView
166166
animateView()
167167
}
168168

169-
var ballState = 0
169+
var isBall = false
170170
func changeBall() {
171-
switch ballState {
172-
case 1:
173-
let animation = CABasicAnimation()
174-
animation.keyPath = "cornerRadius"
175-
animation.fromValue = 50
176-
animation.toValue = 10
177-
animation.duration = 0.2
178-
ballView.layer.cornerRadius = 10
179-
ballView.layer.addAnimation(animation, forKey: "radius")
180-
181-
ballState = 0
182-
default:
183-
let animation = CABasicAnimation()
184-
animation.keyPath = "cornerRadius"
185-
animation.fromValue = 10
186-
animation.toValue = 50
187-
animation.duration = 0.2
188-
ballView.layer.cornerRadius = 50
189-
ballView.layer.addAnimation(animation, forKey: "radius")
190-
191-
ballState++
192-
}
193-
171+
isBall = !isBall
194172
let animation = CABasicAnimation()
195-
animation.keyPath = "opacity"
196-
animation.fromValue = 1
197-
animation.toValue = 0
173+
let halfWidth = ballView.frame.width / 2
174+
let cornerRadius: CGFloat = isBall ? halfWidth : 10
175+
animation.keyPath = "cornerRadius"
176+
animation.fromValue = isBall ? 10 : halfWidth
177+
animation.toValue = cornerRadius
198178
animation.duration = 0.2
199-
animation.autoreverses = true
200-
ballView.layer.addAnimation(animation, forKey: "fade")
179+
ballView.layer.cornerRadius = cornerRadius
180+
ballView.layer.addAnimation(animation, forKey: "radius")
201181
}
202182

203183
@IBAction func shapeButtonPressed(sender: AnyObject) {

0 commit comments

Comments
 (0)