Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to build for Swift 4+ #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Plum-o-Meter/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
30 changes: 30 additions & 0 deletions Plum-o-Meter/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,16 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
17 changes: 11 additions & 6 deletions Plum-o-Meter/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Plum_o_Meter" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 2 additions & 0 deletions Plum-o-Meter/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<array>
<string>armv7</string>
</array>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
43 changes: 21 additions & 22 deletions Plum-o-Meter/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class ViewController: UIViewController
{
super.viewDidLoad()

view.multipleTouchEnabled = true
view.isMultipleTouchEnabled = true

label.text = "lay your plums on me."

label.textAlignment = NSTextAlignment.Center
label.textAlignment = NSTextAlignment.center

view.addSubview(label)
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
label.hidden = true
label.isHidden = true

for touch in touches
{
let circle = CircleWithLabel()

circle.drawAtPoint(touch.locationInView(view),
circle.drawAtPoint(location: touch.location(in: view),
force: touch.force / touch.maximumPossibleForce)

circles[touch] = circle
Expand All @@ -46,33 +46,33 @@ class ViewController: UIViewController
highlightHeaviest()
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches where circles[touch] != nil
{
let circle = circles[touch]!

circle.drawAtPoint(touch.locationInView(view),
circle.drawAtPoint(location: touch.location(in: view),
force: touch.force / touch.maximumPossibleForce)
}

highlightHeaviest()
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches where circles[touch] != nil
{
let circle = circles[touch]!

circles.removeValueForKey(touch)
circles.removeValue(forKey: touch)
circle.removeFromSuperlayer()
}

highlightHeaviest()
}

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?)
override func touchesCancelled(_ touches: Set<UITouch>?, with event: UIEvent?)
{
guard let touches = touches else
{
Expand All @@ -91,7 +91,7 @@ class ViewController: UIViewController
{
func getMaxTouch() -> UITouch?
{
return circles.sort({
return circles.sorted(by: {
(a: (UITouch, CircleWithLabel), b: (UITouch, CircleWithLabel)) -> Bool in

return a.0.force > b.0.force
Expand All @@ -104,9 +104,8 @@ class ViewController: UIViewController
}
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Landscape
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
}

override func viewDidLayoutSubviews()
Expand All @@ -125,16 +124,16 @@ class CircleWithLabel: CAShapeLayer
{
super.init()

text.foregroundColor = UIColor.blueColor().CGColor
text.alignmentMode = kCAAlignmentCenter
text.foregroundColor = UIColor.blue.cgColor
text.alignmentMode = CATextLayerAlignmentMode.center
addSublayer(text)

strokeColor = UIColor.blueColor().CGColor
strokeColor = UIColor.blue.cgColor
lineWidth = 5
fillColor = nil
}

override init(layer: AnyObject)
override init(layer: Any)
{
super.init(layer: layer)
}
Expand All @@ -148,7 +147,7 @@ class CircleWithLabel: CAShapeLayer
{
didSet
{
fillColor = isMax ? UIColor.yellowColor().CGColor : nil
fillColor = isMax ? UIColor.yellow.cgColor : nil
}
}

Expand All @@ -157,9 +156,9 @@ class CircleWithLabel: CAShapeLayer
let radius = 120 + (force * 120)

path = UIBezierPath(
ovalInRect: CGRect(
ovalIn: CGRect(
origin: location.offset(dx: radius, dy: radius),
size: CGSize(width: radius * 2, height: radius * 2))).CGPath
size: CGSize(width: radius * 2, height: radius * 2))).cgPath

text.string = String(format: "%.1f%%", force * 100)

Expand All @@ -171,7 +170,7 @@ class CircleWithLabel: CAShapeLayer

extension CGPoint
{
func offset(dx dx: CGFloat, dy: CGFloat) -> CGPoint
func offset(dx: CGFloat, dy: CGFloat) -> CGPoint
{
return CGPoint(x: self.x - dx, y: self.y - dy)
}
Expand Down