@@ -118,6 +118,7 @@ public class DragMenuView: UIView {
118
118
/// - applyStyle: Style drag menu and its every item with this optional function.
119
119
public init ( items: [ String ] , initalSelection: Int , estimatedItemSize: CGFloat , controlBounds: CGRect , direction: DragMenuDirection , margins: CGFloat , backgroundColor: UIColor , highlightedColor: UIColor , textColor: UIColor , highlightedTextColor: UIColor , font: UIFont , applyStyle: DragMenuApplyStyleAction ? = nil ) {
120
120
self . direction = direction
121
+ print ( controlBounds)
121
122
super. init ( frame: CGRect (
122
123
x: direction == . horizontal ? - controlBounds . minX + margins : 0 ,
123
124
y: direction == . horizontal ? 0 : - controlBounds. minY + margins,
@@ -134,7 +135,7 @@ public class DragMenuView: UIView {
134
135
menuView. backgroundColor = backgroundColor
135
136
menuView. frame = CGRect (
136
137
x: direction == . horizontal ? - ( CGFloat ( initalSelection) * estimatedItemSize) + controlBounds. minX : 0 ,
137
- y: direction == . horizontal ? 0 : - ( CGFloat ( initalSelection) * estimatedItemSize) + controlBounds. minY - ( controlBounds . size . height / 2 ) ,
138
+ y: direction == . horizontal ? 0 : - ( CGFloat ( initalSelection) * estimatedItemSize) + controlBounds. minY - margins ,
138
139
width: direction == . horizontal ? CGFloat ( items. count) * estimatedItemSize : controlBounds. width,
139
140
height: direction == . horizontal ? controlBounds. height : CGFloat ( items. count) * estimatedItemSize)
140
141
@@ -153,7 +154,7 @@ public class DragMenuView: UIView {
153
154
itemView. font = font
154
155
self . items. append ( itemView)
155
156
menuView. addSubview ( itemView)
156
-
157
+ itemView . debugLayer ( color : . green )
157
158
applyStyle ? ( self , itemView)
158
159
}
159
160
}
@@ -174,7 +175,9 @@ public class DragMenuView: UIView {
174
175
/// - Parameter location: Current position of touch on drag menu.
175
176
public func updateMenu( for position: CGPoint ) {
176
177
// Check if menu is scrollable
177
- if menuView. frame. width > frame. width || menuView. frame. height > frame. height {
178
+ let scrollable = ( menuView. frame. minX < 0 || menuView. frame. maxX > frame. size. width) || // check horizontal scrollable bounds
179
+ ( menuView. frame. minY < 0 || menuView. frame. maxY > frame. size. height) // check vertical scrollable bounds
180
+ if scrollable {
178
181
// Update menu position
179
182
switch direction {
180
183
case . horizontal:
@@ -380,7 +383,8 @@ public class DragMenuView: UIView {
380
383
public override func touchesMoved( _ touches: Set < UITouch > , with event: UIEvent ? ) {
381
384
guard isOpen,
382
385
let dragMenu = dragMenu,
383
- let touchLocation = touches. first? . location ( in: dragMenu) else { return }
386
+ let touchLocation = touches. first? . location ( in: dragMenu)
387
+ else { return }
384
388
dragMenu. updateMenu ( for: touchLocation)
385
389
}
386
390
0 commit comments