Skip to content

Commit

Permalink
完善 Adapters注册通知时的处理
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Nov 7, 2018
1 parent f02c137 commit 6a545e6
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 36 deletions.
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '2.2.2'
s.version = '2.2.3'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
23 changes: 13 additions & 10 deletions SJVideoPlayer/Adapters/SJEdgeControlLayerAdapters.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,32 @@
#import "SJEdgeControlLayerAdapters.h"

NS_ASSUME_NONNULL_BEGIN
@implementation SJEdgeControlLayerAdapters
@implementation SJEdgeControlLayerAdapters {
id _notifyToken;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if ( !self ) return nil;
[self _observeOrientationChangeOfStatusBarNotify];
self.autoAdjustTopSpacing = YES;
return self;
}

- (void)setAutoAdjustTopSpacing:(BOOL)autoAdjustTopSpacing {
_autoAdjustTopSpacing = autoAdjustTopSpacing;
if ( autoAdjustTopSpacing ) [self _observeOrientationChangeOfStatusBarNotify];
else [self _removeNotify];
- (void)dealloc {
if ( _notifyToken ) [NSNotificationCenter.defaultCenter removeObserver:_notifyToken];
}

- (void)_observeOrientationChangeOfStatusBarNotify {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_updateTopLayout:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}

- (void)_removeNotify {
[NSNotificationCenter.defaultCenter removeObserver:self];
__weak typeof(self) _self = self;
_notifyToken = [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationWillChangeStatusBarOrientationNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
__strong typeof(_self) self = _self;
if ( !self ) return;
[self _updateTopLayout:note];
}];
}

- (void)_updateTopLayout:(nullable NSNotification *)notify {
if ( !_autoAdjustTopSpacing ) return;
if ( !_topAdapter ) return;
UIInterfaceOrientation orientation = notify?[notify.userInfo[UIApplicationStatusBarOrientationUserInfoKey] integerValue]: UIApplication.sharedApplication.statusBarOrientation;
switch ( orientation ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ @interface SJVideoPlayerControlSettingRecorder ()

@end

@implementation SJVideoPlayerControlSettingRecorder
@implementation SJVideoPlayerControlSettingRecorder {
id _notifyToken;
}

- (instancetype)initWithSettings:(void (^)(SJEdgeControlLayerSettings *))settings {
self = [super init];
if ( !self ) return nil;
_settings = settings;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(settingsPlayerNotification:)
name:SJSettingsPlayerNotification
object:nil];

__weak typeof(self) _self = self;
_notifyToken = [NSNotificationCenter.defaultCenter addObserverForName:SJSettingsPlayerNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
__strong typeof(_self) self = _self;
if ( !self ) return;
if ( self.settings ) self.settings(note.object);
}];
return self;
}
- (void)settingsPlayerNotification:(NSNotification *)notifi {
if ( self.settings ) self.settings(notifi.object);
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
if ( _notifyToken ) [NSNotificationCenter.defaultCenter removeObserver:_notifyToken];
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ @interface SJFilmEditingControlLayer ()
@end
NS_ASSUME_NONNULL_END

@implementation SJFilmEditingControlLayer
@implementation SJFilmEditingControlLayer {
id _notifyToken;
}

@synthesize btnContainerView = _btnContainerView;
@synthesize screenshotBtn = _screenshotBtn;
Expand All @@ -108,12 +110,17 @@ - (instancetype)initWithFrame:(CGRect)frame {
if ( !self ) return nil;
[self _setupViews];
SJFilmEditingControlLayer.update(^(SJFilmEditingSettings * _Nonnull settings) {});
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingsUpdateNotification:) name:SJFilmEditingSettingsUpdateNotification object:nil];
__weak typeof(self) _self = self;
_notifyToken = [NSNotificationCenter.defaultCenter addObserverForName:SJFilmEditingSettingsUpdateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
__strong typeof(_self) self = _self;
if ( !self ) return;
[self settingsUpdateNotification:note];
}];
return self;
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
if ( _notifyToken ) [[NSNotificationCenter defaultCenter] removeObserver:_notifyToken];

#ifdef SJ_MAC
NSLog(@"SJVideoPlayerLog: %d - %s", (int)__LINE__, __func__);
Expand Down
2 changes: 1 addition & 1 deletion SJVideoPlayer/SJVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ - (void)dealloc {
}

+ (NSString *)version {
return @"v2.2.1";
return @"v2.2.3";
}

+ (instancetype)player {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit 6a545e6

Please sign in to comment.