diff --git a/Wonderful.podspec b/Wonderful.podspec index 4d0bfb4..6089f14 100644 --- a/Wonderful.podspec +++ b/Wonderful.podspec @@ -9,5 +9,6 @@ s.source = { :git => 'https://github.com/dsxNiubility/Wonderful.git', :tag => s. s.requires_arc = true s.ios.deployment_target = '7.0' s.source_files = 'Wonderful/*.{h,m}' +s.dependency 'YYText' end diff --git a/Wonderful/SXHeadLine.m b/Wonderful/SXHeadLine.m index ae3205c..147ea39 100644 --- a/Wonderful/SXHeadLine.m +++ b/Wonderful/SXHeadLine.m @@ -8,6 +8,7 @@ #import "SXHeadLine.h" #import "SXColorGradientView.h" +#import #define kSXHeadLineMargin 10 @@ -31,7 +32,7 @@ @interface SXHeadLine () @property (nonatomic,copy ) actionBlock tapAction; @property (nonatomic,assign) SXMarqueeTapMode tapMode; - +@property (nonatomic, strong) YYTextWeakProxy *weakProxy; @end @implementation SXHeadLine @@ -74,6 +75,8 @@ - (void)removeCompoment{ } - (void)dealloc{ + [self.timer invalidate]; + self.timer = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; } @@ -113,7 +116,9 @@ - (void)start{ if (self.messageArray.count < 2) { return; } - NSTimer *timer = [NSTimer timerWithTimeInterval:_stayDuration target:self selector:@selector(scrollAnimate) userInfo:nil repeats:YES]; + // 使用NSTimer在`repeats`设置为`yes`时NSTimer会持有target造成循环引用, + // 可参考https://stackoverflow.com/questions/16821736/weak-reference-to-nstimer-target-to-prevent-retain-cycle + NSTimer *timer = [NSTimer timerWithTimeInterval:_stayDuration target:self.weakProxy selector:@selector(scrollAnimate) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes]; self.timer = timer; } @@ -245,5 +250,12 @@ - (void)bgButtonPress } } +- (YYTextWeakProxy *)weakProxy { + if (!_weakProxy) { + _weakProxy = [YYTextWeakProxy proxyWithTarget:self]; + } + return _weakProxy; +} + @end diff --git a/WonderfulDemo/Wonderful.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/WonderfulDemo/Wonderful.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/WonderfulDemo/Wonderful.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + +