Skip to content

Commit

Permalink
add new design with new gesture for custom view
Browse files Browse the repository at this point in the history
  • Loading branch information
ragaie committed Sep 2, 2019
1 parent a203035 commit 97b40f4
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 101 deletions.
28 changes: 28 additions & 0 deletions ActionSheetBottom-Chtar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
81CE8C2720077B4D009DA082 /* DatePicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = 81CE8C2420076EC4009DA082 /* DatePicker.xib */; };
81D057262236A8A1004E5E50 /* Picker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81D057252236A8A1004E5E50 /* Picker.swift */; };
81F10293200CC4D500CDE732 /* ChtarBottomSheet.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 81F1028A200CBE1400CDE732 /* ChtarBottomSheet.podspec */; };
DFFCA3D4231D314200BD7BFD /* movie2.mov in Resources */ = {isa = PBXBuildFile; fileRef = DFFCA3D3231D314200BD7BFD /* movie2.mov */; };
DFFCA3D9231D31B400BD7BFD /* picker2.png in Resources */ = {isa = PBXBuildFile; fileRef = DFFCA3D5231D31B400BD7BFD /* picker2.png */; };
DFFCA3DA231D31B400BD7BFD /* date1.png in Resources */ = {isa = PBXBuildFile; fileRef = DFFCA3D6231D31B400BD7BFD /* date1.png */; };
DFFCA3DB231D31B400BD7BFD /* picker1.png in Resources */ = {isa = PBXBuildFile; fileRef = DFFCA3D7231D31B400BD7BFD /* picker1.png */; };
DFFCA3DC231D31B400BD7BFD /* custom1.png in Resources */ = {isa = PBXBuildFile; fileRef = DFFCA3D8231D31B400BD7BFD /* custom1.png */; };
DFFCBD392317E680003969FD /* CustomPicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = DFFCBD382317E680003969FD /* CustomPicker.xib */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -71,6 +76,11 @@
81CE8C2520076EC4009DA082 /* DatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePicker.swift; sourceTree = "<group>"; };
81D057252236A8A1004E5E50 /* Picker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Picker.swift; sourceTree = "<group>"; };
81F1028A200CBE1400CDE732 /* ChtarBottomSheet.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = ChtarBottomSheet.podspec; sourceTree = "<group>"; };
DFFCA3D3231D314200BD7BFD /* movie2.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = movie2.mov; sourceTree = "<group>"; };
DFFCA3D5231D31B400BD7BFD /* picker2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = picker2.png; sourceTree = "<group>"; };
DFFCA3D6231D31B400BD7BFD /* date1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = date1.png; sourceTree = "<group>"; };
DFFCA3D7231D31B400BD7BFD /* picker1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = picker1.png; sourceTree = "<group>"; };
DFFCA3D8231D31B400BD7BFD /* custom1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = custom1.png; sourceTree = "<group>"; };
DFFCBD382317E680003969FD /* CustomPicker.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CustomPicker.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -123,6 +133,7 @@
8117780D1F1F81D9001FA155 /* screen shot */ = {
isa = PBXGroup;
children = (
DFFCA3D2231D30CA00BD7BFD /* New Group */,
8143F9F02237D30E006CCB5A /* movie show.mov */,
8143F9F52237D365006CCB5A /* image1.png */,
8143F9F32237D365006CCB5A /* image2.png */,
Expand Down Expand Up @@ -171,6 +182,18 @@
path = "Library files";
sourceTree = "<group>";
};
DFFCA3D2231D30CA00BD7BFD /* New Group */ = {
isa = PBXGroup;
children = (
DFFCA3D7231D31B400BD7BFD /* picker1.png */,
DFFCA3D5231D31B400BD7BFD /* picker2.png */,
DFFCA3D6231D31B400BD7BFD /* date1.png */,
DFFCA3D8231D31B400BD7BFD /* custom1.png */,
DFFCA3D3231D314200BD7BFD /* movie2.mov */,
);
name = "New Group";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -240,19 +263,24 @@
81A0B36B200B78C200A4A65D /* TableView.xib in Resources */,
8143F9F72237D365006CCB5A /* image2.png in Resources */,
81F10293200CC4D500CDE732 /* ChtarBottomSheet.podspec in Resources */,
DFFCA3D4231D314200BD7BFD /* movie2.mov in Resources */,
8143F9F92237D365006CCB5A /* image1.png in Resources */,
81CE8C2720077B4D009DA082 /* DatePicker.xib in Resources */,
DFFCA3DB231D31B400BD7BFD /* picker1.png in Resources */,
81A0B377200B949000A4A65D /* CollectionCell.xib in Resources */,
DFFCBD392317E680003969FD /* CustomPicker.xib in Resources */,
8143F9EE2237D2FF006CCB5A /* image6.png in Resources */,
8117780B1F1F7EDD001FA155 /* PickerList.xib in Resources */,
811777FE1F1F7EBC001FA155 /* Assets.xcassets in Resources */,
8143F9F62237D365006CCB5A /* image4.png in Resources */,
DFFCA3DA231D31B400BD7BFD /* date1.png in Resources */,
DFFCA3DC231D31B400BD7BFD /* custom1.png in Resources */,
8143F9EF2237D2FF006CCB5A /* image5.png in Resources */,
8143F9EC2237D2FF006CCB5A /* image8.png in Resources */,
811777FC1F1F7EBC001FA155 /* Main.storyboard in Resources */,
81A0B375200B944800A4A65D /* CollectionData.xib in Resources */,
81A0B370200B8ED200A4A65D /* TableCell.xib in Resources */,
DFFCA3D9231D31B400BD7BFD /* picker2.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions ChtarBottomSheet.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ date picker and any data picker ,and any view you can put it in this animateied

s.source_files = 'Library files/*.swift'
s.resources = 'Library files/*.xib'
s.resource_bundle = {'ChtarBottomSheet' => ['Library files/DatePicker.xib','Library files/PickerList.xib']}
s.resource_bundle = {'ChtarBottomSheet' => ['Library files/DatePicker.xib','Library files/PickerList.xib','Library files/CustomPicker.xib']}


end
end
39 changes: 32 additions & 7 deletions Library files/CustomPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
class CustomPicker: UIView,Picker {

@IBOutlet weak var containeView: UIView!

var selectItem : Int! = 0
private var showFlage :Bool! = false
var ID : String! = "customeSheet"
Expand Down Expand Up @@ -61,7 +61,7 @@ class CustomPicker: UIView,Picker {

//MARK : Init SubView
func initSubviews() {

let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "CustomPicker", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
Expand All @@ -82,14 +82,17 @@ class CustomPicker: UIView,Picker {
plurView.alpha = 1

}

//MARK : add action of of all View
func initActionAndDelegete() {
let singleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PickerList.clickheader(_:)))
singleTap.numberOfTapsRequired = 1
plurView.addGestureRecognizer(singleTap)
NotificationCenter.default.addObserver(self, selector: #selector(PickerList.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)

let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
plurView.addGestureRecognizer(gestureRecognizer)

}

///handle rodation of screen
Expand All @@ -99,6 +102,32 @@ class CustomPicker: UIView,Picker {

}
}

@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {


let translation = gestureRecognizer.translation(in: plurView)

if gestureRecognizer.state == .changed {

// note: 'view' is optional and need to be unwrapped

if (self.frame.minY + translation.y) > ( UIScreen.main.bounds.height - self.frame.height) && (self.frame.minY + translation.y) < ( UIScreen.main.bounds.height * 8/9){

self.center = CGPoint(x: self.center.x , y: self.center.y + translation.y)
gestureRecognizer.setTranslation(CGPoint.zero, in: self)
}
}
//dismis view when reach point and user removed his pin
if gestureRecognizer.state == .ended {

if (self.frame.minY + translation.y) > ( UIScreen.main.bounds.height * 4/5){

self.dismissView()
}
}

}

/// show view
func show() {
Expand All @@ -115,13 +144,9 @@ class CustomPicker: UIView,Picker {
var basketTopFrame = self.frame
basketTopFrame.origin.y -= self.sheetHeight
self.frame = basketTopFrame

}, completion: { finished in
// self.customViewToShow.frame = CGRect.init(x: 0, y: 0, width: self.containeView.frame.width, height: self.containeView.frame.height)

if let showBlock = self.showBlock {
showBlock()

}
})
showFlage = true
Expand Down
67 changes: 25 additions & 42 deletions Library files/DatePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import UIKit
@objc public protocol SheetPickerDateDelegate {
func DatePicker(_ datepicker: DatePicker, didSelectDate date: Date)
func DatePicker(_ datepicker: DatePicker, cancelAtDate date: Date)


}


public class DatePicker: UIView ,Picker{

@IBOutlet weak var DoneButton: UIButton!
Expand All @@ -32,9 +29,9 @@ public class DatePicker: UIView ,Picker{
var doneBlock : ((_ date:Date) -> Void)!
var cancelBlock : ((_ date:Date)->Void)?
var buttonTitle : String! = "Done"
var ID : String! = "pickerlist"
var plurView : UIVisualEffectView!

var ID : String! = "pickerlist"
var plurView : UIVisualEffectView!
var pickerLocale : Locale! = Locale.init(identifier: "en")
var pickerMode : UIDatePicker.Mode! = .dateAndTime

Expand Down Expand Up @@ -69,16 +66,7 @@ public class DatePicker: UIView ,Picker{
sheetHeight = frame.size.height
initSubviews()
initActionAndDelegete()


}

deinit {

NotificationCenter.default.removeObserver(self)
}



required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand All @@ -92,8 +80,6 @@ public class DatePicker: UIView ,Picker{
super.layoutSubviews()
}



func initSubviews() {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "DatePicker", bundle: bundle)
Expand All @@ -114,7 +100,7 @@ public class DatePicker: UIView ,Picker{
plurView.frame = CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
plurView.alpha = 1
}

// add action of dropDown
func initActionAndDelegete() {
DoneButton.addTarget(self, action: #selector(DatePicker.selectItem(_:)), for: .touchUpInside)
Expand All @@ -123,61 +109,54 @@ public class DatePicker: UIView ,Picker{
plurView.addGestureRecognizer(singleTap)
NotificationCenter.default.addObserver(self, selector: #selector(DatePicker.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
}

@objc func rotated() {
if ( UIDevice.current.orientation.isLandscape) || UIDevice.current.orientation.isPortrait {
self.dismissView()

}
}

/// show view
func show() {
// set some data for view befor using it
datePicker.locale = pickerLocale
datePicker.datePickerMode = pickerMode
DoneButton.setTitle(buttonTitle, for: .normal)
if showFlage == false {
if showFlage == false {
UIApplication.shared.keyWindow?.addSubview(plurView)
UIApplication.shared.keyWindow?.addSubview(self)
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
var basketTopFrame = self.frame
basketTopFrame.origin.y -= self.sheetHeight
self.frame = basketTopFrame
}, completion: { finished in
// print("Ragaie doors opened!")
})
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
var basketTopFrame = self.frame
basketTopFrame.origin.y -= self.sheetHeight
self.frame = basketTopFrame
}, completion: { finished in
// print("Ragaie doors opened!")
})
showFlage = true
}
}
}







func dismissView() {
UIView.animate(withDuration: 0.2, delay:0, options: .curveEaseOut, animations: {
UIView.animate(withDuration: 0.2, delay:0, options: .curveEaseOut, animations: {
var basketTopFrame = self.frame
basketTopFrame.origin.y += self.sheetHeight
self.frame = basketTopFrame
}, completion: { finished in
self.plurView.removeFromSuperview()
self.self.removeFromSuperview()
// print("view removed !")

// print("view removed !")
})
showFlage = false
}



@objc func selectItem(_ sender: UIButton) -> Void {
if delegate != nil {
delegate.DatePicker(self, didSelectDate: datePicker.date)
}
dismissView()
showFlage = false
showFlage = false
if (doneBlock != nil){
doneBlock(datePicker.date)
}
Expand All @@ -193,7 +172,11 @@ public class DatePicker: UIView ,Picker{
}
dismissView()
}


deinit {
NotificationCenter.default.removeObserver(self)
}

}


Expand Down

0 comments on commit 97b40f4

Please sign in to comment.