Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMBase
Project
Project
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMBase
Commits
72822fd7
Commit
72822fd7
authored
May 14, 2020
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
c638d01e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
309 additions
and
0 deletions
+309
-0
GMActionSheet.swift
GMBase/Classes/Common/GMActionSheet.swift
+209
-0
UIVIewController+GoSettings.swift
GMBase/Classes/Common/UIVIewController+GoSettings.swift
+21
-0
WMBaseViewController+FadeNavigation.h
GMBase/Classes/Common/WMBaseViewController+FadeNavigation.h
+18
-0
WMBaseViewController+FadeNavigation.m
GMBase/Classes/Common/WMBaseViewController+FadeNavigation.m
+61
-0
No files found.
GMBase/Classes/Common/GMActionSheet.swift
0 → 100644
View file @
72822fd7
//
// GMActionSheet.swift
// Gengmei
//
// Created by 汪俊 on 2017/2/7.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
import
UIKit
//import GMBaseSwift
/// item文字的颜色
@objc
public
enum
GMActionSheetItemType
:
Int
{
case
`
default
`
// 默认
case
cancel
// 取消
}
/// alertView item的数据
public
struct
GMActionSheetItemObject
{
var
title
:
String
var
type
:
GMActionSheetItemType
var
color
:
UIColor
var
handler
:
ItemClickBlock
?
init
(
title
:
String
,
type
:
GMActionSheetItemType
,
color
:
UIColor
,
block
:
ItemClickBlock
?)
{
self
.
title
=
title
self
.
type
=
type
self
.
color
=
color
self
.
handler
=
block
}
}
public
typealias
ItemClickBlock
=
(
_
index
:
Int
)
->
Void
/// 日记本详情页编辑日记本弹出的自定义的一个alertView,从底部向上弹出
@objcMembers
public
class
GMActionSheet
:
GMView
{
fileprivate
let
tableView
=
GMTableView
(
frame
:
.
zero
,
style
:
.
grouped
)
fileprivate
var
itemObjs
=
[
GMActionSheetItemObject
]()
fileprivate
let
coverBackView
=
GMView
()
fileprivate
var
alertTitle
=
""
fileprivate
var
cancelItemObj
=
GMActionSheetItemObject
(
title
:
""
,
type
:
.
cancel
,
color
:
UIColor
.
headlineText
,
block
:
nil
)
public
override
func
setup
()
{
super
.
setup
()
self
.
backgroundColor
=
UIColor
.
white
coverBackView
.
addGestureRecognizer
(
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
coverBackTapAction
)
))
coverBackView
.
backgroundColor
=
UIColor
.
black
coverBackView
.
alpha
=
0
coverBackView
.
frame
=
Constant
.
screenBounds
tableView
.
registerCell
(
GMActionSheetCell
.
classForCoder
())
tableView
.
isScrollEnabled
=
false
backgroundColor
=
UIColor
.
background
addSubview
(
tableView
)
tableView
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
Constant
.
screenWidth
,
height
:
0
)
tableView
.
rowHeight
=
49
tableView
.
delegate
=
self
tableView
.
dataSource
=
self
}
// 添加alert title
public
func
addAlertTitle
(
_
title
:
String
,
color
:
UIColor
)
{
alertTitle
=
title
if
title
.
isEmpty
{
return
}
let
header
=
GMView
(
frame
:
CGRect
(
x
:
0
,
y
:
0
,
width
:
Constant
.
screenWidth
,
height
:
49
))
header
.
backgroundColor
=
UIColor
.
white
let
headerTitle
=
GMLabel
(
textColor
:
color
,
fontSize
:
16
)
headerTitle
.
textAlignment
=
.
center
headerTitle
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
Constant
.
screenWidth
,
height
:
49
)
headerTitle
.
text
=
title
header
.
addSubview
(
headerTitle
)
header
.
addBottomLine
()
self
.
tableView
.
tableHeaderView
=
header
}
public
func
addItem
(
title
:
String
,
style
:
GMActionSheetItemType
,
color
:
UIColor
,
handle
:
ItemClickBlock
?
=
nil
)
{
if
style
==
.
default
{
let
itemObj
=
GMActionSheetItemObject
(
title
:
title
,
type
:
style
,
color
:
color
,
block
:
handle
)
itemObjs
.
append
(
itemObj
)
}
else
{
cancelItemObj
=
GMActionSheetItemObject
(
title
:
title
,
type
:
style
,
color
:
color
,
block
:
handle
)
}
}
}
// MARK: - UITableViewDataSource, UITableViewDelegate
@objc
extension
GMActionSheet
:
UITableViewDataSource
,
UITableViewDelegate
{
func
numberOfSections
(
in
tableView
:
UITableView
)
->
Int
{
return
2
}
public
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
if
section
==
0
{
return
itemObjs
.
count
}
return
1
}
public
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
let
cell
=
tableView
.
dequeue
(
cell
:
GMActionSheetCell
.
classForCoder
(),
for
:
indexPath
)
as!
GMActionSheetCell
if
indexPath
.
section
==
0
{
let
obj
=
itemObjs
[
indexPath
.
row
]
cell
.
label
.
text
=
obj
.
title
cell
.
label
.
textColor
=
obj
.
color
cell
.
bottomLine
.
isHidden
=
(
indexPath
.
row
==
itemObjs
.
count
-
1
)
}
else
{
cell
.
label
.
text
=
cancelItemObj
.
title
cell
.
label
.
textColor
=
cancelItemObj
.
color
}
return
cell
}
public
func
tableView
(
_
tableView
:
UITableView
,
viewForFooterInSection
section
:
Int
)
->
UIView
?
{
if
section
==
0
{
return
UIView
()
}
else
{
return
nil
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
heightForFooterInSection
section
:
Int
)
->
CGFloat
{
if
section
==
0
{
return
10
}
else
{
return
0
}
}
func
tableView
(
_
tableView
:
UITableView
,
viewForHeaderInSection
section
:
Int
)
->
UIView
?
{
return
UIView
()
}
func
tableView
(
_
tableView
:
UITableView
,
heightForHeaderInSection
section
:
Int
)
->
CGFloat
{
return
0.01
}
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
if
indexPath
.
section
==
0
{
if
itemObjs
[
indexPath
.
row
]
.
handler
!=
nil
{
itemObjs
[
indexPath
.
row
]
.
handler
!
(
indexPath
.
row
)
}
hide
()
}
else
{
if
cancelItemObj
.
handler
!=
nil
{
cancelItemObj
.
handler
!
(
indexPath
.
row
)
}
hide
()
}
}
override
public
func
willMove
(
toSuperview
newSuperview
:
UIView
?)
{
if
newSuperview
!=
nil
{
tableView
.
reloadData
()
var
itemCout
=
0
if
alertTitle
.
isEmpty
{
itemCout
=
itemObjs
.
count
+
1
}
else
{
itemCout
=
itemObjs
.
count
+
2
}
let
alertViewHeight
=
itemCout
*
49
+
10
tableView
.
height
=
CGFloat
(
alertViewHeight
)
var
resizedHeight
=
CGFloat
(
alertViewHeight
)
if
#available(iOS 11.0, *)
{
resizedHeight
+=
newSuperview
!.
safeAreaInsets
.
bottom
}
self
.
frame
=
CGRect
(
x
:
0
,
y
:
Constant
.
screenHeight
,
width
:
Constant
.
screenWidth
,
height
:
resizedHeight
)
UIView
.
animate
(
withDuration
:
0.25
,
animations
:
{
self
.
top
=
Constant
.
screenHeight
-
self
.
height
self
.
coverBackView
.
alpha
=
0.5
})
}
}
}
// MARK: - action
@objc
extension
GMActionSheet
{
public
dynamic
func
show
()
{
UIApplication
.
shared
.
keyWindow
?
.
addSubview
(
coverBackView
)
UIApplication
.
shared
.
keyWindow
?
.
addSubview
(
self
)
}
public
dynamic
func
hide
()
{
UIView
.
animate
(
withDuration
:
0.25
,
animations
:
{
self
.
top
=
Constant
.
screenHeight
self
.
coverBackView
.
alpha
=
0
},
completion
:
{
(
_
)
in
self
.
removeFromSuperview
()
self
.
coverBackView
.
removeFromSuperview
()
})
}
@objc
dynamic
func
coverBackTapAction
()
{
hide
()
}
}
@objcMembers
class
GMActionSheetCell
:
GMTableViewCell
{
var
label
=
GMLabel
(
textAlignment
:
.
center
,
backgroundColor
:
UIColor
.
clear
,
textColor
:
UIColor
.
headlineText
,
fontSize
:
15
)
override
func
setup
()
{
super
.
setup
()
contentView
.
addSubview
(
label
)
label
.
snp
.
makeConstraints
{
(
make
)
in
make
.
edges
.
equalTo
(
UIEdgeInsets
.
zero
)
}
}
}
GMBase/Classes/Common/UIVIewController+GoSettings.swift
0 → 100644
View file @
72822fd7
//
// UIVIewController+GoSettings.swift
// Gengmei
//
// Created by Terminator on 2017/7/4.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
import
UIKit
@objc
public
extension
UIViewController
{
//跳转到APP设置界面 打开通知以及其其他的
@objc
public
func
goToAppSystemSettings
()
{
if
#available(iOS 10.0, *)
{
UIApplication
.
shared
.
open
(
URL
(
string
:
UIApplication
.
openSettingsURLString
)
!
,
options
:
[:],
completionHandler
:
nil
)
}
else
{
UIApplication
.
shared
.
openURL
(
URL
(
string
:
UIApplication
.
openSettingsURLString
)
!
)
}
}
}
GMBase/Classes/Common/WMBaseViewController+FadeNavigation.h
0 → 100644
View file @
72822fd7
//
// WMBaseViewController+FadeNavigation.h
// Gengmei
//
// Created by wangyang on 2017/6/6.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "WMBaseViewController.h"
@interface
WMBaseViewController
(
FadeNavigation
)
@property
(
nonatomic
,
assign
)
CGFloat
animationDistance
;
// 考虑到如果scrollview y偏移量为负数, 添加次当做scrollView最初的Y偏移量
@property
(
nonatomic
,
assign
)
CGFloat
contentOffsetY
;
// 返回当前的alpha值
-
(
CGFloat
)
animationBar
:(
OCNavigationBar
*
)
bar
withScrollView
:(
UIScrollView
*
)
scrollView
;
@end
GMBase/Classes/Common/WMBaseViewController+FadeNavigation.m
0 → 100644
View file @
72822fd7
//
// WMBaseViewController+FadeNavigation.m
// Gengmei
//
// Created by wangyang on 2017/6/6.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "WMBaseViewController+FadeNavigation.h"
#import <objc/runtime.h>
@implementation
WMBaseViewController
(
FadeNavigation
)
-
(
void
)
setAnimationDistance
:(
CGFloat
)
animationDistance
{
objc_setAssociatedObject
(
self
,
@selector
(
animationDistance
),
@
(
animationDistance
),
OBJC_ASSOCIATION_RETAIN
);
}
-
(
CGFloat
)
animationDistance
{
NSNumber
*
_animationDistance
=
objc_getAssociatedObject
(
self
,
_cmd
);
if
(
_animationDistance
==
nil
)
{
return
0
;
}
else
{
return
[
_animationDistance
doubleValue
];
}
}
-
(
void
)
setContentOffsetY
:
(
CGFloat
)
contentOffsetY
{
objc_setAssociatedObject
(
self
,
@selector
(
contentOffsetY
),
@
(
contentOffsetY
),
OBJC_ASSOCIATION_RETAIN
);
}
-
(
CGFloat
)
contentOffsetY
{
NSNumber
*
_contentOffsetY
=
objc_getAssociatedObject
(
self
,
_cmd
);
if
(
_contentOffsetY
==
nil
)
{
return
0
;
}
return
_contentOffsetY
.
doubleValue
;
}
-
(
CGFloat
)
animationBar
:
(
OCNavigationBar
*
)
bar
withScrollView
:
(
UIScrollView
*
)
scrollView
{
CGFloat
offsetY
=
scrollView
.
contentOffset
.
y
;
if
(
self
.
contentOffsetY
>
0
)
{
offsetY
=
self
.
contentOffsetY
;
}
CGFloat
alpha
=
MIN
(
1
.
0
,
offsetY
/
self
.
animationDistance
);
if
(
offsetY
>
self
.
animationDistance
)
{
// 导航栏不透明
bar
.
backgroundColor
=
[
UIColor
colorWithWhite
:
1
alpha
:
alpha
];
bar
.
titleLabel
.
textColor
=
[
UIColor
colorWithWhite
:
0
alpha
:
alpha
];
bar
.
isShowShadow
=
YES
;
}
else
{
// 导航栏渐变到透明
bar
.
backgroundColor
=
[
UIColor
colorWithWhite
:
1
alpha
:
alpha
];
bar
.
titleLabel
.
textColor
=
[
UIColor
colorWithWhite
:
0
alpha
:
alpha
];
bar
.
isShowShadow
=
NO
;
}
self
.
navigationBar
.
titleLabel
.
hidden
=
alpha
==
0
;
return
alpha
;
}
@end
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