Skip to content

Instantly share code, notes, and snippets.

import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var redBox: UIView!
var specialLayoutGuide: UILayoutGuide!
init() {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)
dataSource = self
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var redBox: UIView!
var specialLayoutGuide: UILayoutGuide!
init() {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)
dataSource = self
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var redBox: UIView!
init() {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)
dataSource = self
}
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var redBox: UIView!
init() {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)
dataSource = self
}
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var redBox: UIView!
init() {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)
dataSource = self
}
import UIKit
class ViewController: UIViewController {
var redBox: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Trying to migrate some old frame based code to Auto Layout
redBox = UIView()

Long-press FIRST before scrubbing

Similar to Safari and long-pressing on a photo or GIF, this already brings up the Haptic Touch menu for share options.

Use edges of screen for next/prev, center for scrubbing video

The ergonomics of this aren't great on large phones, makes something as common as swiping between posts quite an effort. Plus I find the "dual layer" thing kinda confusing, for instance the Apple News app does this.

Swipe up/down instead (AKA TikTok style)

# Long-press FIRST before scrubbing
Similar to Safari and long-pressing on a photo or GIF, this already brings up the Haptic Touch menu for share options.
# Use edges of screen for next/prev, center for scrubbing video
The ergonomics of this aren't great on large phones, makes something as common as swiping between posts quite an effort. Plus I find the "dual layer" thing kinda confusing, for instance the Apple News app does this.
# Swipe up/down instead (AKA TikTok style)
import SwiftUI
struct ContentView: View {
var body: some View {
List {
ForEach(0 ..< 5, id: \.self) { index in
Button {
print("Tapped index \(index)")
} label: {
HStack {
@christianselig
christianselig / swiftui-magic-number-helper.md
Last active July 27, 2022 21:24
Make magic numbers more accessible in SwiftUI

More Accessible Magic Numbers

A lot of StackOverflow answers for dealing with things in SwiftUI sometimes being positioned not how you want (for example) understandably solve it with a magic number to put something where they want.

The downside of this is that it likely only works at the default Dynamic Type size, so anyone with larger or smaller text settings (for accessibility reasons, for instance) will likely have a layout that doesn't look as optimized (for instance, if you assume 24.0 is a good number based on the default .large size, if they have their phone set to accessibilityExtraExtraExtraLarge, 24.0 will likely be way too small).

So here's a quick helper extension that simply scales a number based on the Dynamic Type size, so that 24.0 will increase and decrease with the user's Dynamic Type setting.

// Extending BinaryFloatingPoint so that this ext