Skip to content

vospennikov/InteractiveImageView

Repository files navigation

InteractiveImageView

Swift Platform Framework Swift Package Manager GitHub

InteractiveImageView is an open-source library that provides experience showing images like a Photos App on iPhone. (Tap to zoom, pinch and pan gestures, rotation with keep position, motion inertia). The view supports UIKit and SwiftUI framework.

Demo

Usage

SwiftUI

@StatevartapLocation:CGPoint=.zero
InteractiveImage(image:.init(named:"Iceland"),zoomInteraction:.init(location:tapLocation,scale:1.2,animated:true)

SwiftUI before iOS 16 didn't support touch location detection. To zoom to the touch location, you could use theGesturespackage.

.onTouchGesture(count:2){gesturein
tapLocation=gesture.location
}

UIKit

varinteractiveImageView=InteractiveImageView(maxScale:2.0)
interactiveImageView.image=UIImage(named:"Iceland")

funcgestureHandler(_ sender:UITapGestureRecognizer){
letlocation=sender.location(in:imageView)
interactiveImageView.zoom(to:location,scale:2.0,animated:true)
}

Installation

Swift Package Manager

Add the following dependency to yourPackage.swiftfile:

.package(url:"https://github /vospennikov/InteractiveImageView.git",.upToNextMinor(from:"1.1.0"))

License

Gestures is available under the MIT license. See the LICENSE file for more info.