我希望用户点击tableviewcell中的图片来展开我试过的 github上的4个库与自动布局无关。
我也发现它在Objective-c中,甚至不能与Xcode 7 MHFacebookImageViewer一起使用。 https://github.com/michaelhenry/MHFacebookImageViewer
也是https://github.com/aleckretch/AKImageViewer但在objective-c
是否有任何swift库?
答案 0 :(得分:2)
如果您想在swift中使用此库,则必须Add Bridging Header
AKImageViewer - ,例如我从这个库中获取一点点代码
var aKImageViewerViewController: AKImageViewerController = AKImageViewerViewController()
aKImageViewerViewController.image = UIImage.imageName("lion.png")
aKImageViewerViewController.imgCancel = UIImage.imageNamed("btn_cancel.png")
self.view.addSubview(aKImageViewerViewController.view)
aKImageViewerViewController.centerPictureFromPoint(CGPointMake(0, 0), ofSize: CGSizeMake(30, 30), withCornerRadius: 1.0)
MHFacebookImageViewer - 例如,我从这个库中获取一个方法,你可以在swift中使用它
func setupImageViewer() {
// Some code
}
func setupImageViewerWithCompletionOnOpen(open: MHFacebookImageViewerOpeningBlock, onClose close: MHFacebookImageViewerClosingBlock) {
// Some code
}
答案 1 :(得分:0)
这里是您需要实现的特殊动画,想象你有两个相似的矩形,它们的比例是相同的,然后我们使用W1 / W2 = H1 / H2的等式得到H2 =(W2 / W1) H1如果你对数学部分不感兴趣,请看一下代码,它基本上是两个函数,用于zoomIn动画和zoomOut,以回到绝对坐标系。
let zoomImageView = UIImageView()
let blackBackgroundView = UIView()
let navBarCoverView = UIView()// to hide navigation bar
let tabBarCoverView = UIView() // to hide tab bar
var statusImageView: UIImageView?
func animateImageView(statusImageView: UIImageView) {
self.statusImageView = statusImageView
//to get absolute coordinate system
if let startingFrame = statusImageView.superview?.convertRect(statusImageView.frame, toView: nil) {
statusImageView.alpha = 0
blackBackgroundView.frame = self.view.frame
blackBackgroundView.backgroundColor = UIColor.blackColor()
blackBackgroundView.alpha = 0
view.addSubview(blackBackgroundView)
navBarCoverView.frame = CGRectMake(0, 0, 1000, 20 + 44)
navBarCoverView.backgroundColor = UIColor.blackColor()
navBarCoverView.alpha = 0
if let keyWindow = UIApplication.sharedApplication().keyWindow {
keyWindow.addSubview(navBarCoverView)
tabBarCoverView.frame = CGRectMake(0, keyWindow.frame.height - 49, 1000, 49)
tabBarCoverView.backgroundColor = UIColor.blackColor()
tabBarCoverView.alpha = 0
keyWindow.addSubview(tabBarCoverView)
}
zoomImageView.backgroundColor = UIColor.redColor()
zoomImageView.frame = startingFrame
zoomImageView.userInteractionEnabled = true
zoomImageView.image = statusImageView.image
zoomImageView.contentMode = .ScaleAspectFill
zoomImageView.clipsToBounds = true
view.addSubview(zoomImageView)
zoomImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "zoomOut"))
UIView.animateWithDuration(0.75, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.5, options: .CurveEaseOut, animations: { () -> Void in
let height = (self.view.frame.width / startingFrame.width) * startingFrame.height
let y = self.view.frame.height / 2 - height / 2
self.zoomImageView.frame = CGRectMake(0, y, self.view.frame.width, height)
self.blackBackgroundView.alpha = 1
self.navBarCoverView.alpha = 1
self.tabBarCoverView.alpha = 1
}, completion: nil)
}
}
func zoomOut() {
if let startingFrame = statusImageView!.superview?.convertRect(statusImageView!.frame, toView: nil) {
UIView.animateWithDuration(0.75, animations: { () -> Void in
self.zoomImageView.frame = startingFrame
self.blackBackgroundView.alpha = 0
self.navBarCoverView.alpha = 0
self.tabBarCoverView.alpha = 0
}, completion: { (didComplete) -> Void in
self.zoomImageView.removeFromSuperview()
self.blackBackgroundView.removeFromSuperview()
self.navBarCoverView.removeFromSuperview()
self.tabBarCoverView.removeFromSuperview()
self.statusImageView?.alpha = 1
})
}
}
}