From d8b33c80fcdcb3a9d9bde19204ae19699b668374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=A5=BF=E6=B6=9B?= Date: Thu, 18 Feb 2016 18:18:56 +0800 Subject: [PATCH] add delete feature --- .../images/btn_common_delete_wh.png | Bin 0 -> 547 bytes .../images/btn_common_delete_wh@2x.png | Bin 0 -> 980 bytes .../images/btn_common_delete_wh@3x.png | Bin 0 -> 1440 bytes SKPhotoBrowser/SKPhotoBrowser.swift | 32 +++++++++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png create mode 100644 SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png create mode 100644 SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh.png new file mode 100644 index 0000000000000000000000000000000000000000..5b1b65f3263995e02bc4abc2bf4a854d51d4c07c GIT binary patch literal 547 zcmV+;0^I$HP)lf3trgAweQ`3sgd-L@lwcL?KGe*5VUr z6e^#8%afCqmhr6iT~ z`#6x4_9P7fr*&4|Y>Z@pGhhvv2HJtVA)kTUA4>cV>;ormS58=0do3UajOt4Qi`xS|zz>N^Vb8#@rf1->lM8*v{% zpG`DcK-2MC1=yckFNp#ok%R(?6ksEfC1@!SiPjRd6!@14BvQcN{2Ap!d>6)EhH&S` zz5v$_*BO;06GZ@{_`91o%Qp+m0NWw+7lA9_5V&`^f;IlM1hw{ruacG|jY-PJ*ztOj zh9%8Os#+I2eE=RE#;~%%9>D+r002ovPDHLkV1jn!+>QVM literal 0 HcmV?d00001 diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..4ac6f7228c24daa245efba79d9ac271a418a4523 GIT binary patch literal 980 zcmV;_11tQAP)hk$p$Ctw3`8@LEOHt9^pLI4JU!xidAfTh46 zQ_eJ*8pxv)*cVX02UR1hKO5GXJt_j!*Y}9I<;u6S-$XlPy zBN1uWoSK(JT4BCFDIs?jWduPYAOJWq z1t7(~;|gdJ;f-vY=3Agz2>fx!EdkpO*v4r84j7=JM9^tKR9paTJ7Ake*bKSt za1f2~gGeB52E??}Ij{3kvrM;*j%{S(20-WB{}s)$Qf{D5bNhJ-JP5JNqH+yNNks(b zX|%Zv3Y8t2S8AXj;B$da9Ac-8ngflfL*|S zpeIfzVN2k1h4NNZ2Ix7|Db8Q0gsQPJZA;hXblhiALOj#+C5W#>83b+xHP8{kA>bs16qDLv7&sEvC`$Ht z5737?_P&DRarRcG3RP)`Y2W)9MWx>l0oMZBP4W*>m?%_q&Y7_Q0000Zkz# literal 0 HcmV?d00001 diff --git a/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png b/SKPhotoBrowser/SKPhotoBrowser.bundle/images/btn_common_delete_wh@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..600a84f1b900ea5cdfb29483fd41a250accc6112 GIT binary patch literal 1440 zcmV;R1z-A!P)VpSBpMa73| z?SmIo@b+NwKhQiVi25k{A}CV9C-qImD}o|g6k}0ROT7>T@2%3bQe$e)_%P?#ljGUT z%+6$Hc7Go@aI&-W-Cy>bo&EjxoXoV8QY6GW;0fR|U;%gs_yL#z&Ifh@&jK$5iqDu< zLIzv_d;pA=*!LOW0l(q6AteK*fpZM@zYciUQ!LInDs%uPIUTc;4{)Q8KwOiG0cTqD zIoo*@9!SLin{jg3c@!Q<#efBiJ}u`_cpw!6{;}wj#P4==#`YF)DzGf4?+`Es{07W9 zj;o(Bi$2S-yLb3t4)~q{Lur2+Is!Zf+zTAPB%w8jS>Q$BLEz8s#$E$jzs{GxI4F687d1s4PNb${qJ;F_h6rLjzO-}D-ALV!S;%E{d~y#{<9AdsfAv-_s^ zCOn3IoVy}KL=EB)a4zs2EWQGM1a1NL1_-Jt`~loS=j6lS$I&MNH=tb_>1*3c&-gWf zd0>0xFzd%0@Fnm%x^Vpu)6WBT0GH&n&msk!5lK8RsWW0gU}7}jIN&U@9~9cM8d&dG zvjuDbR@n-~WWaj#v#43%E8rmTByem+-3j1p;3stUu@Bf*Q4`?)j@Gxp&z)mTq8G~$bY(&N6&9MO0pmIC!@xxrx|fpwdGmPZ*rhNvz}J_E#w)hl z_F3ymx6D33TsPr7e0{(kTsIX1YD+2x1piC*MJfi=7BL_&VnASGF`y{DwHd3+q|Cl_ zOA|{SP&XtEO@&kpkTg{AgBTE)SPYOXNC<-%;0JGMsMGIDBFW??vzlG*%%UA~DdV*|Q1KPl5^aHq~i1+4L)9g@w!-PkRyn~4tt+Q8N5x%!_+Pj)?y9)DAzg&t1yEM{mY3F<_9@!F0zKA` zpnr${bF@4smM#ZM>;nVDi5z!^xBAmrj0Jrj7~n-*8wxYCiF8Er-ey^d;?q#Oxkp|8G`!Rh+YnT6L2B_e;hr` uV574R9NYGO4x=9weumBpU&SEn>E~ZAl~91?KQsaW0000 Void } public let SKPHOTO_LOADING_DID_END_NOTIFICATION = "photoLoadingDidEndNotification" @@ -39,7 +40,8 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe public var displayBackAndForwardButton: Bool = true public var disableVerticalSwipe: Bool = false public var isForceStatusBarHidden: Bool = false - + public var displayDelete: Bool = false + // actions private var actionSheet: UIActionSheet! private var activityViewController: UIActivityViewController! @@ -58,6 +60,10 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe private var doneButtonShowFrame: CGRect = CGRect(x: 5, y: 5, width: 44, height: 44) private var doneButtonHideFrame: CGRect = CGRect(x: 5, y: -20, width: 44, height: 44) + private var deleteButton: UIButton! + private var deleteButtonShowFrame: CGRect = CGRect(x: UIScreen.mainScreen().bounds.size.width - 60, y: 5, width: 44, height: 44) + private var deleteButtonHideFrame: CGRect = CGRect(x: UIScreen.mainScreen().bounds.size.width - 60, y: -20, width: 44, height: 44) + // photo's paging private var visiblePages: Set = Set() private var initialPageIndex: Int = 0 @@ -213,6 +219,19 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe doneButton.alpha = 0.0 view.addSubview(doneButton) + // delete + let deleteImage = UIImage(named: "SKPhotoBrowser.bundle/images/btn_common_delete_wh", inBundle: bundle, compatibleWithTraitCollection: nil) ?? UIImage() + deleteButton = UIButton(type: UIButtonType.Custom) + deleteButton.setImage(deleteImage, forState: UIControlState.Normal) + deleteButton.frame = deleteButtonHideFrame + deleteButton.imageEdgeInsets = UIEdgeInsetsMake(15.25, 15.25, 15.25, 15.25) + deleteButton.backgroundColor = .clearColor() + deleteButton.addTarget(self, action: "deleteButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) + deleteButton.alpha = 0.0 + if displayDelete { + view.addSubview(deleteButton) + } + // action button toolActionButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "actionButtonPressed") toolActionButton.tintColor = .whiteColor() @@ -602,6 +621,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe prepareForClosePhotoBrowser() dismissViewControllerAnimated(true) { self.delegate?.didDismissAtPageIndex?(self.currentPageIndex) + self.delegate?.didDeleted?(self.photos as! [SKPhoto]) } } @@ -820,6 +840,16 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate, UIActionShe } } + // MARK: - Button + public func deleteButtonPressed(sender: UIButton) { + photos.removeAtIndex(currentPageIndex) + if photos.count == 0 { + dismissPhotoBrowser() + } else { + reloadData() + } + } + // MARK: Action Button public func actionButtonPressed() { let photo = photoAtIndex(currentPageIndex)