The topic animation was not restarted when the application was debackgrounded

This commit is contained in:
ylecollen 2014-12-19 11:45:30 +01:00
parent 45be269b5e
commit d9c26e1420
2 changed files with 37 additions and 3 deletions

View file

@ -31,6 +31,7 @@
- (void)dismissKeyboard;
- (void)startTopicAnimation;
- (void)stopTopicAnimation;
// return YES if the animation has been stopped
- (BOOL)stopTopicAnimation;
@end

View file

@ -26,12 +26,26 @@
// do not start the topic animation asap
NSTimer * animationTimer;
// restart a killed animation when the application is debackgrounded
BOOL restartAnimationWhenActive;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *displayNameTextFieldTopConstraint;
@end
@implementation RoomTitleView
- (id) initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
}
return self;
}
- (void)dealloc {
if (messagesListener && _mxRoom) {
[_mxRoom removeListener:messagesListener];
@ -41,6 +55,21 @@
// stop any animation
[self stopTopicAnimation];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)appEnteredBackground {
restartAnimationWhenActive = [self stopTopicAnimation];
}
- (void)appEnteredForeground {
if (restartAnimationWhenActive) {
[self startTopicAnimation];
restartAnimationWhenActive = NO;
}
}
- (void)refreshDisplay {
@ -179,7 +208,7 @@
}];
}
- (void)stopTopicAnimation {
- (BOOL)stopTopicAnimation {
// stop running timers
if (animationTimer) {
[animationTimer invalidate];
@ -196,7 +225,11 @@
label = nil;
[self addSubview:_topicTextField];
return YES;
}
return NO;
}
- (void)dismissKeyboard {
@ -209,7 +242,7 @@
[self startTopicAnimation];
}
- (void) setFrame:(CGRect)frame {
- (void)setFrame:(CGRect)frame {
// restart only if there is a frame update
BOOL restartAnimation = !CGRectEqualToRect(CGRectIntegral(frame), CGRectIntegral(self.frame));