Skip to content

Commit

Permalink
Merge pull request #2 from lekshmiraveendranath/allowFullscreen
Browse files Browse the repository at this point in the history
Allow fullscreen Spotlights
  • Loading branch information
lekshmiraveendranath authored Feb 25, 2018
2 parents 226cf8e + fe5fc89 commit 6acfc87
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 94 deletions.
4 changes: 1 addition & 3 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

}

14 changes: 9 additions & 5 deletions Example/Example/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -13,13 +17,13 @@
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.047058823530000002" green="0.24444955069999999" blue="0.55719177649999996" alpha="1" colorSpace="calibratedRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
<point key="canvasLocation" x="-182" y="391"/>
</scene>
</scenes>
</document>
24 changes: 12 additions & 12 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="jdP-K4-PsP">
<device id="retina5_5" orientation="portrait">
<device id="retina5_9" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
Expand All @@ -21,20 +21,20 @@
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="724"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Background" translatesAutoresizingMaskIntoConstraints="NO" id="Wha-OU-3b4">
<rect key="frame" x="0.0" y="64" width="414" height="672"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="724"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Spotlight" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nTu-q0-rPh">
<rect key="frame" x="97.000000000000014" y="184" width="220.33333333333337" height="60"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Spotlight" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.80000000000000004" translatesAutoresizingMaskIntoConstraints="NO" id="nTu-q0-rPh">
<rect key="frame" x="77.666666666666686" y="120" width="220" height="60"/>
<fontDescription key="fontDescription" name="Futura-Bold" family="Futura" pointSize="46"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O7o-NU-QC2">
<rect key="frame" x="293" y="629" width="105" height="35"/>
<rect key="frame" x="254" y="583" width="105" height="35"/>
<fontDescription key="fontDescription" name="Futura-CondensedExtraBold" family="Futura" pointSize="18"/>
<state key="normal" title="Start Tutorial">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand All @@ -44,7 +44,7 @@
</connections>
</button>
<view alpha="0.69999999999999996" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WqJ-pZ-8Wj">
<rect key="frame" x="199" y="601" width="16" height="90"/>
<rect key="frame" x="179.66666666666666" y="555" width="16" height="90"/>
<color key="backgroundColor" red="0.047058823529411764" green="0.24313725490196078" blue="0.55686274509803924" alpha="1" colorSpace="calibratedRGB"/>
<color key="tintColor" red="0.0" green="0.20000000000000001" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
Expand All @@ -63,8 +63,8 @@
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="O7o-NU-QC2" secondAttribute="trailing" constant="16" id="HWQ-nw-HU4"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="Wha-OU-3b4" secondAttribute="trailing" id="Vh4-mS-Qa7"/>
<constraint firstItem="WqJ-pZ-8Wj" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Y74-BX-mtI"/>
<constraint firstItem="Wha-OU-3b4" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="gig-Oa-kn8"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="Wha-OU-3b4" secondAttribute="bottom" id="o1A-ux-fbW"/>
<constraint firstItem="Wha-OU-3b4" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="gig-Oa-kn8"/>
<constraint firstAttribute="bottom" secondItem="Wha-OU-3b4" secondAttribute="bottom" id="o1A-ux-fbW"/>
<constraint firstItem="Wha-OU-3b4" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="oMF-Fi-MgO"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
Expand All @@ -91,10 +91,10 @@
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="jdP-K4-PsP" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="qnZ-rb-txg">
<rect key="frame" x="0.0" y="20" width="414" height="44"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" translucent="NO" id="qnZ-rb-txg">
<rect key="frame" x="0.0" y="44" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" red="0.047058823529411764" green="0.24444955065359478" blue="0.55719177645016338" alpha="1" colorSpace="calibratedRGB"/>
<color key="barTintColor" red="0.047058823530000002" green="0.24444955069999999" blue="0.55719177649999996" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</textAttributes>
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>1.3.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
26 changes: 13 additions & 13 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ class ViewController: UIViewController {

@IBOutlet weak var spotlightLabel: UILabel!
@IBOutlet weak var verticalView: UIView!

@IBAction func startTutorial() {

Spotlight.delay = 4.0
Spotlight.showInfoBackground = false
Spotlight.delay = 5.0

guard let rightBB1 = navigationItem.rightBarButtonItem, let leftBB1 = navigationItem.leftBarButtonItem else { return }
guard let rightBB1 = navigationItem.rightBarButtonItem,
let leftBB1 = navigationItem.leftBarButtonItem,
let navBar = navigationController?.navigationBar else { return }

let n1 = SpotlightNode(text: "Show spotlight on a bar button item", target: .barButton(rightBB1))
let n2 = SpotlightNode(text: "Moved spotlight to the title using a point and radius", target: .point(CGPoint(x: view.bounds.width / 2.0, y: 44), radius: 25))
let n3 = SpotlightNode(text: "Moved the spotlight again", target: .barButton(leftBB1))
let n4 = SpotlightNode(text: "Can higlight individual views, and this view can move around to prevent intersection with spotlight", target: .view(verticalView))
let n5 = SpotlightNode(text: "", target: .point(CGPoint(x: view.bounds.width / 2.0, y: 214), radius: 116))
let n0 = SpotlightNode(text: "Sit back and let Spotlight auto advance, or tap anywhere on screen to advance manually", target: .point(.zero, radius: 0))
let n1 = SpotlightNode(text: "Show spotlight on a bar button item", target: .barButton(leftBB1))
let n2 = SpotlightNode(text: "Moved spotlight to the title using a point and radius", target: .point(CGPoint(x: view.bounds.width / 2.0, y: navBar.frame.midY), radius: 30))
let n3 = SpotlightNode(text: "Moved the spotlight again. Targets can be views, barbuttons, tab bar items, points and more", target: .barButton(rightBB1))
let n4 = SpotlightNode(text: "The Info view can move around to prevent intersection with spotlight", target: .view(verticalView))
let n5 = SpotlightNode(text: "The End", target: .view(spotlightLabel))

let nodes = [n1, n2, n3, n4, n5]
Spotlight().startIntro(from: self, withNodes: nodes)
let nodes = [n0, n1, n2, n3, n4, n5]
Spotlight().startIntro(from: self, withNodes: nodes)
}

}

2 changes: 1 addition & 1 deletion LRSpotlight.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LRSpotlight"
s.version = "1.2.0"
s.version = "1.3.0"
s.swift_version = "4.0.0"
s.license = { :type => 'MIT', :file => "License.md" }
s.summary = "Introductory walkthrough framework for iOS Apps"
Expand Down
4 changes: 4 additions & 0 deletions Spotlight.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
413B98F12029861300EF3606 /* SpotlightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413B98EB2029861300EF3606 /* SpotlightViewController.swift */; };
413B98F22029861300EF3606 /* SpotlightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413B98EC2029861300EF3606 /* SpotlightView.swift */; };
413B98F32029861300EF3606 /* UIKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413B98ED2029861300EF3606 /* UIKitExtensions.swift */; };
41CB6A77203DEAF4006C0DB5 /* SpotlightTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41CB6A76203DEAF4006C0DB5 /* SpotlightTarget.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,6 +27,7 @@
413B98EB2029861300EF3606 /* SpotlightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpotlightViewController.swift; sourceTree = "<group>"; };
413B98EC2029861300EF3606 /* SpotlightView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpotlightView.swift; sourceTree = "<group>"; };
413B98ED2029861300EF3606 /* UIKitExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIKitExtensions.swift; sourceTree = "<group>"; };
41CB6A76203DEAF4006C0DB5 /* SpotlightTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotlightTarget.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -70,6 +72,7 @@
children = (
413B98E82029861300EF3606 /* Spotlight.swift */,
413B98E92029861300EF3606 /* SpotlightNode.swift */,
41CB6A76203DEAF4006C0DB5 /* SpotlightTarget.swift */,
413B98EC2029861300EF3606 /* SpotlightView.swift */,
413B98EB2029861300EF3606 /* SpotlightViewController.swift */,
413B98EA2029861300EF3606 /* SpotlightViewController+UISetup.swift */,
Expand Down Expand Up @@ -163,6 +166,7 @@
413B98F32029861300EF3606 /* UIKitExtensions.swift in Sources */,
413B98F12029861300EF3606 /* SpotlightViewController.swift in Sources */,
413B98EE2029861300EF3606 /* Spotlight.swift in Sources */,
41CB6A77203DEAF4006C0DB5 /* SpotlightTarget.swift in Sources */,
413B98F02029861300EF3606 /* SpotlightViewController+UISetup.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion Spotlight/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>1.3.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
41 changes: 3 additions & 38 deletions Spotlight/Sources/SpotlightNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,15 @@ import Foundation
import UIKit

public struct SpotlightNode {

var text: String
var target: SpotlightTarget

var textColor: UIColor = .white
var font: UIFont = UIFont(name: "Futura", size: 18)!
public var textColor: UIColor = .white
public var font: UIFont = UIFont(name: "Futura", size: 18)!

public init(text: String, target: SpotlightTarget) {
self.text = text
self.target = target
}

public enum SpotlightTarget {
case view(UIView)
case barButton(UIBarButtonItem)
case point(CGPoint, radius: CGFloat)
case rect(CGRect)

var targetView: UIView {
let target: UIView
switch self {
case let .view(view):
target = view
case let .barButton(barButtonItem):
target = barButtonItem.value(forKey: "view") as! UIView
case let .point(center, radius):
target = UIView(frame: CGRect(x: 0, y: 0, width: radius * 2, height: radius * 2))
target.center = center
case let .rect(frame):
target = UIView(frame: frame)
}
return target
}

func path(translater: UIView) -> UIBezierPath {
let translatedFrame = targetView.convert(targetView.bounds, to: translater)
let spotlightFrame = translatedFrame.insetBy(dx: -8.0, dy: -8.0) // Add some breathing space for the spotlight
return UIBezierPath(roundedRect: spotlightFrame, cornerRadius:spotlightFrame.height / 2.0)
}

func infinitesmalPath(translater: UIView) -> UIBezierPath {
let spotlightFrame = targetView.convert(targetView.bounds, to: translater)
let spotlightCenter = CGPoint(x: spotlightFrame.midX, y: spotlightFrame.midY)
return UIBezierPath(roundedRect: CGRect(origin: spotlightCenter, size: CGSize.zero), cornerRadius: 0)
}

}
}
52 changes: 52 additions & 0 deletions Spotlight/Sources/SpotlightTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SpotlightNode.swift
// Spotlight
//
// Created by Lekshmi Raveendranathapanicker on 2/21/18.
// Copyright © 2018 Lekshmi Raveendranathapanicker. All rights reserved.
//

import Foundation

public enum SpotlightTarget {

case view(UIView)
case barButton(UIBarButtonItem)
case tabBarItem(UITabBarController, Int)
case point(CGPoint, radius: CGFloat)
case rect(CGRect)

var targetView: UIView {
let target: UIView
switch self {
case let .view(view):
target = view
case let .barButton(barButtonItem):
target = barButtonItem.value(forKey: "view") as! UIView
case let .tabBarItem(tabBarController, index):
let tabBarItems = tabBarController.tabBar.subviews.filter({ $0.isUserInteractionEnabled })
guard index > -1, tabBarItems.count > index else { return UIView() }
let tabBarItemView = tabBarItems[index]
let frame = CGRect(x: tabBarItemView.frame.midX - 22, y: tabBarController.tabBar.frame.origin.y, width: 44, height: 44)
target = UIView(frame: frame)
case let .point(center, radius):
target = UIView(frame: CGRect(x: 0, y: 0, width: radius * 2, height: radius * 2))
target.center = center
case let .rect(frame):
target = UIView(frame: frame)
}
return target
}

func path(translater: UIView) -> UIBezierPath {
let translatedFrame = targetView.convert(targetView.bounds, to: translater)
let spotlightFrame = translatedFrame.insetBy(dx: -8.0, dy: -8.0) // Add some breathing space for the spotlight
return UIBezierPath(roundedRect: spotlightFrame, cornerRadius: spotlightFrame.height / 2.0)
}

func infinitesmalPath(translater: UIView) -> UIBezierPath {
let spotlightFrame = targetView.convert(targetView.bounds, to: translater)
let spotlightCenter = CGPoint(x: spotlightFrame.midX, y: spotlightFrame.midY)
return UIBezierPath(roundedRect: CGRect(origin: spotlightCenter, size: CGSize.zero), cornerRadius: 0)
}
}
Loading

0 comments on commit 6acfc87

Please sign in to comment.