Skip to content

LiYanan2004/Perspective

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perspective

Simple view modifier to warp perspective of any SwiftUI view.

High performance, real-time distortion filter powered by Metal.

Platforms

  • iOS 17.0+
  • macOS 14.0+
  • tvOS 17.0+

Usage

You can use warpPerspectiveEffect(topLeftPoint:bottomLeftPoint:bottomRightPoint:topRightPoint:) on any SwiftUI view.

@State private var topLeft: CGPoint = CGPoint(x: 0, y: 0)
@State private var bottomLeft: CGPoint = CGPoint(x: 0, y: 1)
@State private var bottomRight: CGPoint = CGPoint(x: 1, y: 1)
@State private var topRight: CGPoint = CGPoint(x: 1, y: 0)

ContentView()
    .warpPerspectiveEffect(
        topLeftPoint: topLeft,
        bottomLeftPoint: bottomLeft,
        bottomRightPoint: bottomRight,
        topRightPoint: topRight
    )

It can also be used as an image filter, equivalent to CIPerspectiveCorrection from Core Image.

Here is an example:

Credits

The calculation part of this package uses the algorithm from:

Credits has been included in the source file.

About

Simple view modifier to warp perspective of any SwiftUI view.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •