Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
3879aac8
Commit
3879aac8
authored
Aug 24, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added custom show/hide gestures
parent
58cd9ddb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
54 deletions
+51
-54
1Weather/UI/View controllers/Today/TodayViewController.swift
+9
-1
1Weather/UI/View controllers/WidgetPromotion/Animators/PromotionPresentationAnimator.swift
+1
-1
1Weather/UI/View controllers/WidgetPromotion/WidgetPromotionController.swift
+41
-52
No files found.
1Weather/UI/View controllers/Today/TodayViewController.swift
View file @
3879aac8
...
...
@@ -73,7 +73,15 @@ class TodayViewController: UIViewController {
}
@objc
private
func
handleNotificationButton
()
{
self
.
coordinator
.
openNotificationsScreen
()
#if DEBUG
if
#available(iOS 14, *)
{
let
promo
=
WidgetPromotionController
(
coordinator
:
WidgetPromotionCoordinator
(
parentViewController
:
self
))
present
(
promo
,
animated
:
true
)
}
#else
fatalError
(
"Remove in release"
)
#endif
// self.coordinator.openNotificationsScreen()
}
}
...
...
1Weather/UI/View controllers/WidgetPromotion/Animators/PromotionPresentationAnimator.swift
View file @
3879aac8
...
...
@@ -26,7 +26,7 @@ class PromotionPresentationAnimator: NSObject, UIViewControllerAnimatedTransitio
height
:
contentHeight
)
container
.
addSubview
(
toViewController
.
view
)
UIView
.
animate
(
withDuration
:
transitionDuration
(
using
:
transitionContext
))
{
toViewController
.
view
.
frame
.
origin
.
y
=
container
.
frame
.
height
-
contentHeight
toViewController
.
view
.
frame
.
origin
.
y
=
container
.
bounds
.
height
*
0.46
}
completion
:
{
finished
in
transitionContext
.
completeTransition
(
finished
)
}
...
...
1Weather/UI/View controllers/WidgetPromotion/WidgetPromotionController.swift
View file @
3879aac8
...
...
@@ -20,12 +20,8 @@ class WidgetPromotionController: UIViewController {
private
let
stackView
=
UIStackView
()
private
let
footerView
=
UIView
()
private
let
learnButton
=
UIButton
()
private
var
initialTouchPoint
=
CGPoint
(
x
:
0
,
y
:
0
)
private
lazy
var
panGesture
:
UIPanGestureRecognizer
=
{
let
gesture
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
#selector(
handlePanGesture(sender:)
)
)
gesture
.
delegate
=
self
return
gesture
}()
private
let
fullView
:
CGFloat
=
UIScreen
.
main
.
bounds
.
height
-
UIScreen
.
main
.
bounds
.
height
*
0.9
private
let
partialView
:
CGFloat
=
UIScreen
.
main
.
bounds
.
height
*
0.46
//Public
var
controllerContentHeight
:
CGFloat
{
...
...
@@ -99,26 +95,32 @@ class WidgetPromotionController: UIViewController {
}
}
@objc
private
func
handlePanGesture
(
sender
:
UIPanGestureRecognizer
)
{
let
touchPoint
=
sender
.
location
(
in
:
self
.
view
?
.
window
)
let
originalOffsetY
=
UIScreen
.
main
.
bounds
.
height
-
self
.
view
.
bounds
.
height
switch
sender
.
state
{
case
.
began
:
initialTouchPoint
=
touchPoint
@objc
private
func
handlePanGesture
(
recognizer
:
UIPanGestureRecognizer
)
{
let
translation
=
recognizer
.
translation
(
in
:
self
.
view
)
let
velocity
=
recognizer
.
velocity
(
in
:
self
.
view
)
let
y
=
self
.
view
.
frame
.
minY
switch
recognizer
.
state
{
case
.
changed
:
if
touchPoint
.
y
-
initialTouchPoint
.
y
>
0
{
view
.
frame
.
origin
.
y
=
originalOffsetY
+
(
touchPoint
.
y
-
initialTouchPoint
.
y
)
self
.
view
.
frame
=
CGRect
(
x
:
0
,
y
:
y
+
translation
.
y
,
width
:
view
.
frame
.
width
,
height
:
view
.
frame
.
height
)
recognizer
.
setTranslation
(
CGPoint
.
zero
,
in
:
self
.
view
)
case
.
ended
:
var
duration
=
velocity
.
y
<
0
?
Double
((
y
-
fullView
)
/
-
velocity
.
y
)
:
Double
((
partialView
-
y
)
/
velocity
.
y
)
duration
=
duration
>
0.3
?
0.3
:
duration
if
velocity
.
y
>=
0
{
self
.
dismiss
(
animated
:
true
)
}
case
.
cancelled
,
.
ended
:
if
touchPoint
.
y
-
initialTouchPoint
.
y
>
80
{
close
()
}
else
{
UIView
.
animate
(
withDuration
:
0.25
,
animations
:
{
self
.
view
.
frame
.
origin
.
y
=
originalOffsetY
})
else
{
UIView
.
animate
(
withDuration
:
duration
)
{
self
.
view
.
frame
=
CGRect
(
x
:
0
,
y
:
self
.
fullView
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
)
}
completion
:
{[
weak
self
]
_
in
if
(
velocity
.
y
<
0
)
{
self
?
.
scrollView
.
isScrollEnabled
=
true
}
}
}
break
default
:
break
}
...
...
@@ -141,7 +143,9 @@ class WidgetPromotionController: UIViewController {
@available(iOS 14, *)
private
extension
WidgetPromotionController
{
func
prepareView
()
{
// view.addGestureRecognizer(panGesture)
let
gesture
=
UIPanGestureRecognizer
(
target
:
self
,
action
:
#selector(
handlePanGesture(recognizer:)
)
)
gesture
.
delegate
=
self
view
.
addGestureRecognizer
(
gesture
)
view
.
clipsToBounds
=
true
view
.
layer
.
cornerRadius
=
24
...
...
@@ -260,11 +264,6 @@ extension WidgetPromotionController: UIScrollViewDelegate {
if
scrollView
.
contentOffset
.
y
==
scrollView
.
contentSize
.
height
-
scrollView
.
frame
.
height
{
AppAnalytics
.
shared
.
log
(
event
:
.
ANALYTICS_WIDGET_BOTTOM_SCROLLED
)
}
// if scrollView.contentOffset.y < 0 {
// let originalOffsetY = UIScreen.main.bounds.height - self.view.bounds.height
// view.frame.origin.y = originalOffsetY - (scrollView.contentOffset.y - initialTouchPoint.y)
// return
// }
}
}
...
...
@@ -272,27 +271,17 @@ extension WidgetPromotionController: UIScrollViewDelegate {
//MARK:- UIGesture Delegate
@available(iOS 14, *)
extension
WidgetPromotionController
:
UIGestureRecognizerDelegate
{
// func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// if scrollView.contentOffset.y > 0 {
// return false
// }
//
// scrollView.contentOffset.y = 0
// return true
// }
// func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
// shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// // Do not begin the pan until the swipe fails.
// if otherGestureRecognizer != self.panGesture {
// print("ScrollView Offset \(scrollView.contentOffset.y)")
// if scrollView.contentOffset.y >= 0 {
// return false
// }
//
// return true
// }
//
// return false
// }
func
gestureRecognizer
(
_
gestureRecognizer
:
UIGestureRecognizer
,
shouldRecognizeSimultaneouslyWith
otherGestureRecognizer
:
UIGestureRecognizer
)
->
Bool
{
let
gesture
=
(
gestureRecognizer
as!
UIPanGestureRecognizer
)
let
direction
=
gesture
.
velocity
(
in
:
view
)
.
y
let
y
=
view
.
frame
.
minY
if
(
y
==
fullView
&&
scrollView
.
contentOffset
.
y
==
0
&&
direction
>
0
)
||
(
y
==
partialView
)
{
scrollView
.
isScrollEnabled
=
false
}
else
{
scrollView
.
isScrollEnabled
=
true
}
return
false
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment