diff --git a/Demo/PanControllerExample/Base/HWBaseViewController.m b/Demo/PanControllerExample/Base/HWBaseViewController.m index d78a866..65c0e51 100644 --- a/Demo/PanControllerExample/Base/HWBaseViewController.m +++ b/Demo/PanControllerExample/Base/HWBaseViewController.m @@ -76,8 +76,8 @@ - (BOOL)anchorModalToLongForm { return NO; } -- (HWPanModalShadow)contentShadow { - return PanModalShadowMake([UIColor yellowColor], 10, CGSizeMake(0, 2), 1); +- (HWPanModalShadow *)contentShadow { + return [[HWPanModalShadow alloc] initWithColor:[UIColor yellowColor] shadowRadius:10 shadowOffset:CGSizeMake(0, 2) shadowOpacity:1]; } //- (UIViewAnimationOptions)transitionAnimationOptions { diff --git a/Demo/PanControllerExample/Dynamic/HWDynamicHeightViewController.m b/Demo/PanControllerExample/Dynamic/HWDynamicHeightViewController.m index b419bcc..859f647 100644 --- a/Demo/PanControllerExample/Dynamic/HWDynamicHeightViewController.m +++ b/Demo/PanControllerExample/Dynamic/HWDynamicHeightViewController.m @@ -25,7 +25,7 @@ @interface HWDynamicHeightViewController () @property (nonatomic, strong) UIButton *changeShadowButton; @property (nonatomic, strong) UIButton *clearShadowButton; -@property (nonatomic, assign) HWPanModalShadow shadowConfig; +@property (nonatomic, strong) HWPanModalShadow *shadowConfig; // corner @property (nonatomic, strong) UIButton *changeRoundCornerButton; @@ -132,12 +132,12 @@ - (void)onTapChangeLong { } - (void)onTapDefaultShadow { - self.shadowConfig = PanModalShadowMake([UIColor blueColor], 8, CGSizeMake(0, 2), 1); + self.shadowConfig = [[HWPanModalShadow alloc] initWithColor:[UIColor blueColor] shadowRadius:8 shadowOffset:CGSizeMake(0, 2) shadowOpacity:1]; [self hw_panModalSetNeedsLayoutUpdate]; } - (void)onTapClearShadow { - self.shadowConfig = PanModalShadowNil(); + self.shadowConfig = [HWPanModalShadow panModalShadowNil]; [self hw_panModalSetNeedsLayoutUpdate]; } @@ -188,7 +188,7 @@ - (PanModalHeight)longFormHeight { return self.longHeight; } -- (HWPanModalShadow)contentShadow { +- (HWPanModalShadow *)contentShadow { return self.shadowConfig; } diff --git a/Demo/PanControllerExample/TestViewPanModal/HWSimplePanModalView.m b/Demo/PanControllerExample/TestViewPanModal/HWSimplePanModalView.m index 37c1454..5d55ab0 100644 --- a/Demo/PanControllerExample/TestViewPanModal/HWSimplePanModalView.m +++ b/Demo/PanControllerExample/TestViewPanModal/HWSimplePanModalView.m @@ -110,8 +110,8 @@ - (UIScrollView *)panScrollable { return self.tableView; } -- (HWPanModalShadow)contentShadow { - return PanModalShadowMake([UIColor systemPinkColor], 10, CGSizeMake(1, 1), 1); +- (HWPanModalShadow *)contentShadow { + return [[HWPanModalShadow alloc] initWithColor:[UIColor systemPinkColor] shadowRadius:10 shadowOffset:CGSizeMake(1, 1) shadowOpacity:1]; } //- (BOOL)allowsTouchEventsPassingThroughTransitionView { diff --git a/HWPanModal.podspec b/HWPanModal.podspec index fb45d61..c7ae169 100644 --- a/HWPanModal.podspec +++ b/HWPanModal.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'HWPanModal' - s.version = '0.9.7' + s.version = '0.9.8' s.summary = 'HWPanModal is used to present controller and drag to dismiss.' # This description is used to generate tags and improve search results. diff --git a/HWPanModal.xcodeproj/project.pbxproj b/HWPanModal.xcodeproj/project.pbxproj index fc4c4d1..7141c1c 100644 --- a/HWPanModal.xcodeproj/project.pbxproj +++ b/HWPanModal.xcodeproj/project.pbxproj @@ -133,7 +133,6 @@ 7EA0F56B230D5B7300ED20D2 /* HWPanModalPresentationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HWPanModalPresentationDelegate.m; sourceTree = ""; }; 7EA0F56C230D5B7300ED20D2 /* HWPanModalPresentationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWPanModalPresentationDelegate.h; sourceTree = ""; }; 7EA0F56E230D5B7400ED20D2 /* UIViewController+Presentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Presentation.h"; sourceTree = ""; }; - 7EA0F56F230D5B7400ED20D2 /* UIViewController+LayoutHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+LayoutHelper.m"; sourceTree = ""; }; 7EA0F570230D5B7400ED20D2 /* UIViewController+PanModalDefault.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+PanModalDefault.m"; sourceTree = ""; }; 7EA0F571230D5B7400ED20D2 /* HWPanModalPresentable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HWPanModalPresentable.h; sourceTree = ""; }; 7EA0F572230D5B7400ED20D2 /* UIViewController+Presentation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Presentation.m"; sourceTree = ""; }; @@ -501,7 +500,6 @@ 7EA0F56E230D5B7400ED20D2 /* UIViewController+Presentation.h */, 7EA0F572230D5B7400ED20D2 /* UIViewController+Presentation.m */, 7EA0F574230D5B7400ED20D2 /* UIViewController+LayoutHelper.h */, - 7EA0F56F230D5B7400ED20D2 /* UIViewController+LayoutHelper.m */, ); path = Presentable; sourceTree = ""; diff --git a/Podfile.lock b/Podfile.lock index 19991ef..1ee856c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - HWPanModal (0.9.5) + - HWPanModal (0.9.7) - Masonry (1.1.0) - MJRefresh (3.5.0) - SnapKit (5.0.1) @@ -21,7 +21,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - HWPanModal: b6c51a2fd3ab5cfde868eec840c9e2d7465d745e + HWPanModal: 2340d953661dbeadd1f041cde9e059c0704c873a Masonry: 678fab65091a9290e40e2832a55e7ab731aad201 MJRefresh: 6afc955813966afb08305477dd7a0d9ad5e79a16 SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb diff --git a/Sources/Animator/HWPanModalPresentationAnimator.m b/Sources/Animator/HWPanModalPresentationAnimator.m index 450ce36..522141b 100644 --- a/Sources/Animator/HWPanModalPresentationAnimator.m +++ b/Sources/Animator/HWPanModalPresentationAnimator.m @@ -141,7 +141,7 @@ - (void)animateDismissal:(id)context { - (void)springDismiss:(id )context fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC presentable:(UIViewController *)presentable panView:(UIView *)panView { CGFloat offsetY = 0; - HWPanModalShadow shadowConfig = [presentable contentShadow]; + HWPanModalShadow *shadowConfig = [presentable contentShadow]; if (shadowConfig.shadowColor) { // we should make the panView move further to hide the shadow effect. offsetY = offsetY + shadowConfig.shadowRadius + shadowConfig.shadowOffset.height; diff --git a/Sources/Controller/HWPanModalPresentationController.m b/Sources/Controller/HWPanModalPresentationController.m index ea232e8..f09950d 100644 --- a/Sources/Controller/HWPanModalPresentationController.m +++ b/Sources/Controller/HWPanModalPresentationController.m @@ -314,7 +314,7 @@ - (void)resetRoundedCornersToView:(UIView *)view { } - (void)updateContainerViewShadow { - HWPanModalShadow shadow = [[self presentable] contentShadow]; + HWPanModalShadow *shadow = [[self presentable] contentShadow]; if (shadow.shadowColor) { [self.panContainerView updateShadow:shadow.shadowColor shadowRadius:shadow.shadowRadius shadowOffset:shadow.shadowOffset shadowOpacity:shadow.shadowOpacity]; } else { diff --git a/Sources/Presentable/HWPanModalHeight.h b/Sources/Presentable/HWPanModalHeight.h index 7580918..998b8d9 100644 --- a/Sources/Presentable/HWPanModalHeight.h +++ b/Sources/Presentable/HWPanModalHeight.h @@ -33,28 +33,6 @@ CG_INLINE PanModalHeight PanModalHeightMake(PanModalHeightType heightType, CGFlo return modalHeight; } -struct HWPanModalShadow { - UIColor *shadowColor; - CGFloat shadowRadius; - CGSize shadowOffset; - float shadowOpacity; -}; - -typedef struct HWPanModalShadow HWPanModalShadow; - -CG_INLINE HWPanModalShadow PanModalShadowMake(UIColor *shadowColor, CGFloat shadowRadius, CGSize shadowOffset, float shadowOpacity) { - HWPanModalShadow shadowConfig; - shadowConfig.shadowColor = shadowColor; - shadowConfig.shadowRadius = shadowRadius; - shadowConfig.shadowOffset = shadowOffset; - shadowConfig.shadowOpacity = shadowOpacity; - return shadowConfig; -} - -CG_INLINE HWPanModalShadow PanModalShadowNil() { - return PanModalShadowMake([UIColor clearColor], 0, CGSizeZero, 0); -} - static inline BOOL HW_FLOAT_IS_ZERO(CGFloat value) { return (value > -FLT_EPSILON) && (value < FLT_EPSILON); } diff --git a/Sources/Presentable/HWPanModalPresentable.h b/Sources/Presentable/HWPanModalPresentable.h index 4d0642c..2e9bc85 100644 --- a/Sources/Presentable/HWPanModalPresentable.h +++ b/Sources/Presentable/HWPanModalPresentable.h @@ -11,6 +11,7 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -271,7 +272,7 @@ typedef NS_ENUM(NSInteger, PresentingViewControllerAnimationStyle) { * presented content shadow * Default is None config */ -- (HWPanModalShadow)contentShadow; +- (HWPanModalShadow *)contentShadow; #pragma mark - Indicator config diff --git a/Sources/Presentable/UIViewController+PanModalDefault.m b/Sources/Presentable/UIViewController+PanModalDefault.m index 3ee0d0a..04d33bd 100644 --- a/Sources/Presentable/UIViewController+PanModalDefault.m +++ b/Sources/Presentable/UIViewController+PanModalDefault.m @@ -172,8 +172,8 @@ - (CGFloat)cornerRadius { return 8; } -- (HWPanModalShadow)contentShadow { - return PanModalShadowMake(nil, 0, CGSizeZero, 0); +- (HWPanModalShadow *)contentShadow { + return [HWPanModalShadow panModalShadowNil]; } - (BOOL)showDragIndicator { diff --git a/Sources/View/HWPanModalShadow.h b/Sources/View/HWPanModalShadow.h new file mode 100644 index 0000000..ab5604c --- /dev/null +++ b/Sources/View/HWPanModalShadow.h @@ -0,0 +1,26 @@ +// +// HWPanModalShadow.h +// Pods +// +// Created by hb on 2023/8/3. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface HWPanModalShadow : NSObject + +@property (nonatomic, strong) UIColor *shadowColor; +@property (nonatomic, assign) CGFloat shadowRadius; +@property (nonatomic, assign) CGSize shadowOffset; +@property (nonatomic, assign) CGFloat shadowOpacity; + +- (instancetype)initWithColor:(UIColor *)shadowColor shadowRadius:(CGFloat)shadowRadius shadowOffset:(CGSize)shadowOffset shadowOpacity:(CGFloat)shadowOpacity; + ++ (instancetype)panModalShadowNil; + + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/View/HWPanModalShadow.m b/Sources/View/HWPanModalShadow.m new file mode 100644 index 0000000..efbbbd8 --- /dev/null +++ b/Sources/View/HWPanModalShadow.m @@ -0,0 +1,28 @@ +// +// HWPanModalShadow.m +// Pods +// +// Created by hb on 2023/8/3. +// + +#import "HWPanModalShadow.h" + +@implementation HWPanModalShadow + +- (instancetype)initWithColor:(UIColor *)shadowColor shadowRadius:(CGFloat)shadowRadius shadowOffset:(CGSize)shadowOffset shadowOpacity:(CGFloat)shadowOpacity { + self = [super init]; + if (self) { + _shadowColor = shadowColor; + _shadowRadius = shadowRadius; + _shadowOffset = shadowOffset; + _shadowOpacity = shadowOpacity; + } + + return self; +} + ++ (instancetype)panModalShadowNil { + return [[HWPanModalShadow alloc] initWithColor:[UIColor clearColor] shadowRadius:0 shadowOffset:CGSizeZero shadowOpacity:0]; +} + +@end diff --git a/Sources/View/PanModal/HWPanModalContainerView.m b/Sources/View/PanModal/HWPanModalContainerView.m index 21978e4..8d8807d 100644 --- a/Sources/View/PanModal/HWPanModalContainerView.m +++ b/Sources/View/PanModal/HWPanModalContainerView.m @@ -277,7 +277,7 @@ - (void)addDragIndicatorViewToView:(UIView *)view { } - (void)updateContainerViewShadow { - HWPanModalShadow shadow = [[self presentable] contentShadow]; + HWPanModalShadow *shadow = [[self presentable] contentShadow]; if (shadow.shadowColor) { [self.panContainerView updateShadow:shadow.shadowColor shadowRadius:shadow.shadowRadius shadowOffset:shadow.shadowOffset shadowOpacity:shadow.shadowOpacity]; } else { diff --git a/Sources/View/PanModal/HWPanModalContentView.m b/Sources/View/PanModal/HWPanModalContentView.m index df15337..89200eb 100644 --- a/Sources/View/PanModal/HWPanModalContentView.m +++ b/Sources/View/PanModal/HWPanModalContentView.m @@ -230,8 +230,8 @@ - (CGFloat)cornerRadius { return 8; } -- (HWPanModalShadow)contentShadow { - return PanModalShadowMake(nil, 0, CGSizeZero, 0); +- (HWPanModalShadow *)contentShadow { + return [HWPanModalShadow panModalShadowNil]; } - (BOOL)showDragIndicator { diff --git a/SwiftDemo/ControllerExample/Basic/BasicViewController.swift b/SwiftDemo/ControllerExample/Basic/BasicViewController.swift index ccbeef1..6f7041f 100644 --- a/SwiftDemo/ControllerExample/Basic/BasicViewController.swift +++ b/SwiftDemo/ControllerExample/Basic/BasicViewController.swift @@ -30,6 +30,9 @@ extension BasicViewController { override func transitionAnimationOptions() -> UIView.AnimationOptions { return [.curveLinear] } - + + override func contentShadow() -> HWPanModalShadow { + return HWPanModalShadow(color: UIColor.red, shadowRadius: 10, shadowOffset: CGSizeMake(0, 2), shadowOpacity: 1) + } }