A realistic reflective shimmer to SwiftUI Views that uses device orientation. Position any View relative to device orientation to appear as if through a window or reflected by the screen.

Overview

LookingGlassUI

License - MIT Version

A 3d rotation effect that uses Core Motion to allow SwiftUI views to appear projected in a specific direction and distance relative to the device in real world space.

Shimmer

This rotation effect is especially useful in faking a light reflection to create a shimmering effect when the device rotates. The package includes a default shimmer effect.

Demo

This package is currently used to create a gold shimmer effect on many gold elements in the Old English Wordhord app. Download it to see the effect in action.

Old English Wordhord App Shimmer v001 - Twitter

Download on the App Store

Example App

Check out LookingGlassUIExample to see how to use this package in an iOS app.

Installation

  1. In XCode 12 go to File -> Swift Packages -> Add Package Dependency or in XCode 13 File -> Add Packages
  2. Paste in the repo's url: https://github.com/ryanlintott/LookingGlassUI and select main branch or select by version.

Usage

Import the package using import LookingGlassUI

MotionManager

Before adding any custom views, add the .motionManager view modifier once, somewhere in the heirarchy above any other views or modifiers used in this package.

ContentView()
    .motionManager(updateInterval: 0.1, disabled: false)

ShimmerView

Use ShimmerView if you want a view that acts like Color but with a default shimmer effect. If MotionManager is disabled only the background color will be shown.

ShimmerView(color: .goldShimmer, background: .gold)

.shimmer()

Use .shimmer() view modifier if you want to add a default shimmer effect to another SwiftUI View. If MotionManager is disabled the modifier has no effect.

Text("Hello, World!")
    .shimmer(color: .gold)

LookingGlass

Use LookingGlass if you want to project any SwiftUI view or create your own custom effect. Content appears as if rotated and positioned from the center of the device regardless of positioin on the screen or if it's in a scrollview. If MotionManager is disabled nothing will be shown.

LookingGlass(.reflection, distance: 4000, perspective: 0, pitch: .degrees(45), yaw: .zero, localRoll: .zero, isShowingInFourDirections: false) {
    Text("Hello, World")
        .foregroundColor(.white)
        .frame(width: 500, height: 500)
        .background(Color.red)
}

.deviceRotationEffect()

Use .deviceRotationEffect() if you want to rotate a view based on device rotation. Content is rotated and positioned based on it's own center. If MotionManager is disabled nothing will be shown.

Text("Hello, World")
    .foregroundColor(.white)
    .frame(width: 500, height: 500)
    .background(Color.red)
    .deviceRotationEffect(.reflection, distance: 4000, perspective: 0, pitch: .degrees(10), yaw: .zero, localRoll: .zero, isShowingInFourDirections: false)

Window and Reflection Modes

In window mode a view appears as if your phone is a window looking into a 3d environment.

In reflection mode a view appears as if your phone has a camera pointing out of the screen back at a 3d envrionment. It's not a true reflection as it doesn't take into account the viewer's eye location but it's a useful approximation.

Positioning Views

Views are positioned based on a quaternion or pitch, yaw, and local roll angles. All angles at zero means the view will be visible when the phone is flat with the top pointing away from the user. (see diagram below)

  1. Local Roll rotate the view around the Z axis. 10 degrees will tilt the view counter-clockwise
  2. Pitch will rotate the view around the X axis. 90 degrees will bring the view up directly in front of the user.
  3. Yaw will rotate the view around the Z axis again. 5 degrees will move the view slightly to the left of the user. If you set isShowingInFourDirections to true the view will be copied 3 additional times and rotated at -90, 90, and 180 degrees from the position you chose.
  4. The view is then moved away from the origin based on the distance provided. The direction is dependant on choosing window or reflection.
  5. As the user moves their device around they will always see your view in the location you've set.

Don't worry about device orientation. Although Core Motion doesn't compensate for this, LookingGlassUI does.

LookingGlassUI Rotation Diagram

Additional Rotation Diagrams

3D space is confusing on iOS, especially as Core Motion and SwiftUI's rotation3dEffect each seem to use different axes. I created this diagram to keep track of how each one works. You probably won't need these unless you want to do something more custom.

iOS Rotation Diagrams

Dependencies

Fireblade Math

You might also like...
This is a project about Swift Student Challenge - WWDC22 [Submitted] Detailed walk through video link below.
This is a project about Swift Student Challenge - WWDC22 [Submitted] Detailed walk through video link below.

Oh My Flag The App Oh My Flag helps students get familiar with flags. It is both educating and entertaining with the design of multi-module and intera

Seaglass is a truly native macOS client for Matrix. It is written in Swift and uses the Cocoa user interface framework.
Seaglass is a truly native macOS client for Matrix. It is written in Swift and uses the Cocoa user interface framework.

Seaglass is a truly native macOS client for Matrix. It is written in Swift and uses the Cocoa user interface framework.

EzNews - A simple and easy to use News app for iOS and iPadOS. It uses NewsAPI as its backend

EzNews This was my first proper Swift app. Its a news app made for iOS and iPadO

Home Assistant uses Bundler, Homebrew and Cocoapods to manage build dependencies

Home Assistant for Apple Platforms Getting Started Home Assistant uses Bundler, Homebrew and Cocoapods to manage build dependencies. You'll need Xcode

IOS mobile application that uses URLSession and Firebase
IOS mobile application that uses URLSession and Firebase

DogApp IOS mobile application that uses URLSession and Firebase. First a dog ima

A sliding Sheet from the bottom of the Screen with 3 States build with SwiftUI.
A sliding Sheet from the bottom of the Screen with 3 States build with SwiftUI.

BottomSheet A sliding Sheet from the bottom of the Screen with 3 States build with SwiftUI. Why There have been many different attempts to recreate th

SwiftUI mirroring of Instagram app Home screen
SwiftUI mirroring of Instagram app Home screen

Instasoup Is a quick code excercise, where I wanted to do fast prototaping of the Instagram like home view screen in #SwiftUI Check the source code an

Food App Onboarding screen made with SwiftUI
Food App Onboarding screen made with SwiftUI

OnBoardSwiftUI-Food Food App Onboarding screen made with SwiftUI. App Details Lottie Files are used for Animations. TabView is used for Screen selecti

AllAboutTheWord - A single screen iOS app developed using swiftUI
AllAboutTheWord - A single screen iOS app developed using swiftUI

All-About-The-Word Introduction This is a single screen iOS app developed using

Releases(0.3.1)
  • 0.3.1(Sep 19, 2022)

    • Removed FirebladeMath dependency.
    • Added Quat (replacing Quat4f from FirebladeMath). It uses simd_quatd to store quaternion values and do quaternion math.
    • Quat init by angle uses SwiftUI Angle instead of Double storing radians.
    • Added typealias Vec3 for SIMD3 (replacing Vec3f from FirebladeMath)
    • Vec3 axis static types renamed from axisX to xAxis and so on.
    • Added normalized to Vec3
    • Made DeviceRotationEffectType conform to String, RawRepresentable, CaseIterable, Hashable, Equatable, and Identifiable by self.
    • Added QuaternionDataView to easily display quaternion data for debugging.
    • Added a few basic tests for Quat
    • Removed accessibilityHidden on ShimmerView. It will only show accessibility elements if one of the underlying elements is accessible.
    • Changed several properties in MotionManager to public in case others want to use them for custom effects.
    • Added documentation to MotionManager properties
    • Changed parallaxView so that the offset is zero if motion manager is no sending updates.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Mar 23, 2022)

  • 0.1.10(Jan 25, 2022)

    Updates:

    • Updated the readme, license and gitignore

    Bugfixes:

    • Fixed an issue where ShimmerView and .shimmer would block touches and interfere with VoiceOver selection.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.7(Aug 5, 2021)

Owner
Ryan Lintott
Ryan Lintott
Mousemory remembers cursor position across multiple monitors.

Mousemory remembers cursor positions across multiple monitors. Mousemory A simple macOS utility that remebers mouse position across different monitors

Marut 8 Oct 17, 2022
Demonstration of using UIWindowScene and SwiftUI to provide a native-looking Mac preferences window in Catalyst

CatalystPrefsWindow Ever wondered how to create a more Mac-like preferences window for Catalyst? Perhaps Settings Bundles are too limiting for the kin

Steven Troughton-Smith 148 Dec 27, 2022
Window preview app for MacOS (on the dock) using AltTab.

DockAltTab The #1 Window manager/Task switcher & Companion for AltTab v1.1 download link https://github.com/steventheworker/DockAltTab/releases/downlo

Steven G. 40 Jan 2, 2023
Mac OSX app that displays window previews when hovering over app icon on the Dock.

Dock Window Preview Adds window preview functionality on hover for Mac Dock, an open-source alternative. This is very early in development and it will

Paul Sweeney 32 Dec 26, 2022
100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI

Hacking with SwiftUI 100 Days of SwiftUI Studying through Paul Hudson's "100 Day

Dean Thompson 3 Aug 29, 2022
Guide users through your SwiftUI app with coach marks

Guide users through your SwiftUI app with coach marks

Jake Heiser 15 Nov 22, 2022
SwiftUI-TodoList - This project uses MVVM architecture and UserDefaults to persist data

SwiftUI-TodoList | ├── SwiftUITodoList | ├── Library | ├── Models

Yezan Ahmed 0 Mar 9, 2022
Exposing macOS Services through a Catalyst app

CatalystServices This is a simple example to show how you can implement the macOS Services system in your Catalyst app. The services you expose are pr

Steven Troughton-Smith 33 Oct 26, 2022
Conveniently getting the User Agent through WKWebView

WebKit User Agent Requirements iOS 9.0+ macOS 10.11+ Installation See the subsec

Dmytrii Golovanov 4 Dec 13, 2021
You can share and communicate with developers around the world through the Fabula app.

FabulaItemsProvider This is the source package for the Fabula project. You can share and communicate with developers around the world through the Fabu

jasu 231 Dec 31, 2022