mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Finish ImageViewer
This commit is contained in:
parent
4f7f713fd6
commit
3c1a905e46
4 changed files with 102 additions and 26 deletions
|
|
@ -563,9 +563,11 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
PhoneMainView.instance().changeCurrentView(view.compositeViewDescription())
|
||||
view.imageViewer = image
|
||||
view.imageNameViewer = chatMessage.contents.first!.name.isEmpty ? "" : chatMessage.contents.first!.name
|
||||
view.imagePathViewer = chatMessage.contents.first!.exportPlainFile()
|
||||
PhoneMainView.instance().changeCurrentView(view.compositeViewDescription())
|
||||
|
||||
} else {
|
||||
let previewController = QLPreviewController()
|
||||
self.previewItems = []
|
||||
|
|
|
|||
|
|
@ -1516,8 +1516,12 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
|
|||
|
||||
let cellsPerRow = 1
|
||||
let minimumInterItemSpacing = 1.0
|
||||
let marginsAndInsets = window!.safeAreaInsets.left + window!.safeAreaInsets.right + minimumInterItemSpacing * CGFloat(cellsPerRow - 1)
|
||||
layoutAttributes.bounds.size.width = ((window!.bounds.size.width - marginsAndInsets) / CGFloat(cellsPerRow)).rounded(.down)
|
||||
if window != nil {
|
||||
let marginsAndInsets = window!.safeAreaInsets.left + window!.safeAreaInsets.right + minimumInterItemSpacing * CGFloat(cellsPerRow - 1)
|
||||
layoutAttributes.bounds.size.width = ((window!.bounds.size.width - marginsAndInsets) / CGFloat(cellsPerRow)).rounded(.down)
|
||||
} else {
|
||||
layoutAttributes.bounds.size.width = (UIScreen.main.bounds.size.width / CGFloat(cellsPerRow)).rounded(.down)
|
||||
}
|
||||
return layoutAttributes
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -417,14 +417,14 @@ extension UIView {
|
|||
func setHeight(_ h:CGFloat, animateTime:TimeInterval?=nil) {
|
||||
if let c = self.constraints.first(where: { $0.firstAttribute == .height && $0.relation == .equal }) {
|
||||
c.constant = CGFloat(h)
|
||||
|
||||
if let animateTime = animateTime {
|
||||
UIView.animate(withDuration: animateTime, animations:{
|
||||
if self.superview != nil {
|
||||
if let animateTime = animateTime {
|
||||
UIView.animate(withDuration: animateTime, animations:{
|
||||
self.superview?.layoutIfNeeded()
|
||||
})
|
||||
} else {
|
||||
self.superview?.layoutIfNeeded()
|
||||
})
|
||||
}
|
||||
else {
|
||||
self.superview?.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,18 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
@objc class ImageViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollViewDelegate {
|
||||
|
||||
@objc class ImageViewer: BackNextNavigationView, UICompositeViewDelegate, UIScrollViewDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource {
|
||||
static let compositeDescription = UICompositeViewDescription(ImageViewer.self, statusBar: StatusBarView.self, tabBar: nil, sideMenu: SideMenuView.self, fullscreen: false, isLeftFragment: false,fragmentWith: nil)
|
||||
static func compositeViewDescription() -> UICompositeViewDescription! { return compositeDescription }
|
||||
func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription }
|
||||
|
||||
@objc var imageNameViewer = ""
|
||||
@objc var imagePathViewer = ""
|
||||
@objc var imageViewer = UIImage()
|
||||
var newImageView = UIImageView()
|
||||
let imageViewViewer = UIImageView()
|
||||
let imageScrollView = UIScrollView()
|
||||
var previewItems : [QLPreviewItem?] = []
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
||||
|
|
@ -35,11 +37,23 @@ import Foundation
|
|||
|
||||
shareButton.addTarget(self, action: #selector(shareTextButton), for: .touchUpInside)
|
||||
|
||||
let vWidth = UIScreen.main.bounds.size.width
|
||||
let vHeight = UIScreen.main.bounds.size.height-32.0
|
||||
UIDeviceBridge.displayModeSwitched.readCurrentAndObserve { _ in
|
||||
self.view.backgroundColor = VoipTheme.voipBackgroundBWColor.get()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
let vWidth = self.view.bounds.size.width
|
||||
let vHeight = self.view.bounds.size.height-66
|
||||
|
||||
|
||||
newImageView.removeFromSuperview()
|
||||
imageViewViewer.removeFromSuperview()
|
||||
imageScrollView.removeFromSuperview()
|
||||
|
||||
imageScrollView.delegate = self
|
||||
imageScrollView.frame = CGRectMake(0, 0, vWidth, vHeight)
|
||||
imageScrollView.frame = CGRectMake(0, 66, vWidth, vHeight)
|
||||
imageScrollView.showsVerticalScrollIndicator = true
|
||||
|
||||
imageScrollView.minimumZoomScale = 1.0
|
||||
|
|
@ -49,18 +63,53 @@ import Foundation
|
|||
|
||||
imageViewViewer.contentMode = .scaleAspectFit
|
||||
imageScrollView.addSubview(imageViewViewer)
|
||||
|
||||
self.imageViewViewer.frame = CGRect(x: 0, y: 0, width: vWidth, height: vHeight)
|
||||
self.view.bringSubviewToFront(topBar)
|
||||
|
||||
UIDeviceBridge.displayModeSwitched.readCurrentAndObserve { _ in
|
||||
self.view.backgroundColor = VoipTheme.voipBackgroundBWColor.get()
|
||||
self.imageViewViewer.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height-32.0)
|
||||
}
|
||||
|
||||
let pictureTap = UITapGestureRecognizer(target: self, action: #selector(imageTapped))
|
||||
imageViewViewer.addGestureRecognizer(pictureTap)
|
||||
imageViewViewer.isUserInteractionEnabled = true
|
||||
|
||||
imageViewViewer.image = imageViewer
|
||||
titleLabel.text = imageNameViewer
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
imageViewViewer.image = imageViewer
|
||||
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
|
||||
dismissFullscreenImageRotated()
|
||||
self.viewWillAppear(true)
|
||||
}
|
||||
|
||||
@IBAction func imageTapped(_ sender: UITapGestureRecognizer) {
|
||||
let imageView = sender.view as! UIImageView
|
||||
newImageView = UIImageView(image: imageView.image)
|
||||
newImageView.frame = UIScreen.main.bounds
|
||||
newImageView.frame = CGRectMake(0, 0, UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height-20)
|
||||
newImageView.backgroundColor = .black
|
||||
newImageView.contentMode = .scaleAspectFit
|
||||
newImageView.isUserInteractionEnabled = true
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
|
||||
newImageView.addGestureRecognizer(tap)
|
||||
self.view.addSubview(newImageView)
|
||||
self.navigationController?.isNavigationBarHidden = true
|
||||
self.tabBarController?.tabBar.isHidden = true
|
||||
PhoneMainView.instance().hideStatusBar(true)
|
||||
}
|
||||
|
||||
func dismissFullscreenImageRotated() {
|
||||
self.navigationController?.isNavigationBarHidden = false
|
||||
self.tabBarController?.tabBar.isHidden = false
|
||||
PhoneMainView.instance().hideStatusBar(false)
|
||||
}
|
||||
|
||||
@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
|
||||
self.navigationController?.isNavigationBarHidden = false
|
||||
self.tabBarController?.tabBar.isHidden = false
|
||||
PhoneMainView.instance().hideStatusBar(false)
|
||||
sender.view?.removeFromSuperview()
|
||||
}
|
||||
|
||||
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
||||
return self.imageViewViewer
|
||||
}
|
||||
|
||||
@IBAction func shareTextButton(_ sender: UIButton) {
|
||||
|
|
@ -79,9 +128,30 @@ import Foundation
|
|||
// present the view controller
|
||||
self.present(activityViewController, animated: true, completion: nil)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
let previewController = QLPreviewController()
|
||||
self.previewItems = []
|
||||
|
||||
self.previewItems.append(self.getPreviewItem(filePath: imagePathViewer))
|
||||
|
||||
previewController.dataSource = self
|
||||
previewController.delegate = self
|
||||
PhoneMainView.instance().mainViewController.present(previewController, animated: true, completion: nil)
|
||||
|
||||
}
|
||||
|
||||
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
||||
return self.imageViewViewer
|
||||
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
|
||||
return previewItems.count
|
||||
}
|
||||
|
||||
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
|
||||
return (previewItems[index] as QLPreviewItem?)!
|
||||
}
|
||||
|
||||
func getPreviewItem(filePath: String) -> NSURL{
|
||||
let url = NSURL(fileURLWithPath: filePath)
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue