add delete feature

This commit is contained in:
张西涛 2016-02-18 18:18:56 +08:00
parent 323bc651d3
commit d8b33c80fc
4 changed files with 31 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -14,6 +14,7 @@ import UIKit
optional func willShowActionSheet(photoIndex: Int)
optional func didDismissAtPageIndex(index: Int)
optional func didDismissActionSheetWithButtonIndex(buttonIndex: Int, photoIndex: Int)
optional func didDeleted(notDeleted: [SKPhoto]) -> 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<SKZoomingScrollView> = 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)