Version 1
This commit is contained in:
42
CapCollector/View Components/AlwaysShowPopup.swift
Normal file
42
CapCollector/View Components/AlwaysShowPopup.swift
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2018, Ralf Ebert
|
||||
// License https://opensource.org/licenses/MIT
|
||||
// License https://creativecommons.org/publicdomain/zero/1.0/
|
||||
// Source https://www.ralfebert.de/ios-examples/uikit/choicepopover/
|
||||
|
||||
import UIKit
|
||||
|
||||
/**
|
||||
By default, when you use:
|
||||
|
||||
```
|
||||
controller.modalPresentationStyle = .popover
|
||||
```
|
||||
|
||||
in a horizontally compact environment (iPhone in portrait mode), this option behaves the same as fullScreen.
|
||||
You can make it to always show a popover by using:
|
||||
|
||||
```
|
||||
let presentationController = AlwaysPresentAsPopover.configurePresentation(forController: controller)
|
||||
```
|
||||
*/
|
||||
class AlwaysPresentAsPopover : NSObject, UIPopoverPresentationControllerDelegate {
|
||||
|
||||
// `sharedInstance` because the delegate property is weak - the delegate instance needs to be retained.
|
||||
private static let sharedInstance = AlwaysPresentAsPopover()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
|
||||
return .none
|
||||
}
|
||||
|
||||
static func configurePresentation(forController controller : UIViewController) -> UIPopoverPresentationController {
|
||||
controller.modalPresentationStyle = .popover
|
||||
let presentationController = controller.presentationController as! UIPopoverPresentationController
|
||||
presentationController.delegate = AlwaysPresentAsPopover.sharedInstance
|
||||
return presentationController
|
||||
}
|
||||
|
||||
}
|
52
CapCollector/View Components/CropView.swift
Normal file
52
CapCollector/View Components/CropView.swift
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// CropView.swift
|
||||
// CapFinder
|
||||
//
|
||||
// Created by User on 31.01.18.
|
||||
// Copyright © 2018 User. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@IBDesignable class CropView: UIView {
|
||||
|
||||
@IBInspectable var lineColor: UIColor = UIColor.black
|
||||
|
||||
@IBInspectable var lineWidth: Float = 2
|
||||
|
||||
@IBInspectable var relativeSize: Float = 0.6 {
|
||||
didSet { size = CGFloat(relativeSize) / 2 }
|
||||
}
|
||||
|
||||
private var size: CGFloat = 0.3
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
override func draw(_ rect: CGRect) {
|
||||
let height = rect.height
|
||||
let width = rect.width
|
||||
|
||||
let length = height > width ? width : height
|
||||
|
||||
let center = CGPoint(x: width / 2, y: height / 2)
|
||||
let path = UIBezierPath()
|
||||
|
||||
path.lineWidth = CGFloat(self.lineWidth)
|
||||
lineColor.setStroke()
|
||||
|
||||
path.addArc(
|
||||
withCenter: center,
|
||||
radius: length * size,
|
||||
startAngle: 0,
|
||||
endAngle: .pi * 2,
|
||||
clockwise: true)
|
||||
|
||||
path.stroke()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user