From 87373cdafd6942bdd3c9b747cd0c027e65124f20 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 3 Mar 2016 22:27:45 +0000 Subject: [PATCH] Fix constraints issues on Yosemite when hiding web seed view (OS X) --- macosx/InfoPeersView.xib | 9 ++++--- macosx/InfoPeersViewController.h | 5 ++-- macosx/InfoPeersViewController.m | 44 ++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/macosx/InfoPeersView.xib b/macosx/InfoPeersView.xib index c2bbd7991..bcb323ae4 100644 --- a/macosx/InfoPeersView.xib +++ b/macosx/InfoPeersView.xib @@ -9,9 +9,8 @@ - - + @@ -212,14 +211,16 @@ Multiline Label - + - + + + diff --git a/macosx/InfoPeersViewController.h b/macosx/InfoPeersViewController.h index a66fdd61d..3b74a5a05 100644 --- a/macosx/InfoPeersViewController.h +++ b/macosx/InfoPeersViewController.h @@ -37,12 +37,11 @@ IBOutlet NSTableView * fPeerTable; IBOutlet WebSeedTableView * fWebSeedTable; - CGFloat fWebSeedTableHeight, fSpaceBetweenWebSeedAndPeer; IBOutlet NSTextField * fConnectedPeersField; - IBOutlet NSLayoutConstraint * fWebSeedTableHeightConstraint; - IBOutlet NSLayoutConstraint * fPeerTableTopConstraint; + CGFloat fViewTopMargin; + IBOutlet NSLayoutConstraint * fWebSeedTableTopConstraint; } - (void) setInfoForTorrents: (NSArray *) torrents; diff --git a/macosx/InfoPeersViewController.m b/macosx/InfoPeersViewController.m index 861423aff..3580910a6 100644 --- a/macosx/InfoPeersViewController.m +++ b/macosx/InfoPeersViewController.m @@ -32,6 +32,9 @@ #import "transmission.h" // required by utils.h #import "utils.h" +#define ANIMATION_ID_KEY @"animationId" +#define WEB_SEED_ANIMATION_ID @"webSeed" + @interface InfoPeersViewController (Private) - (void) setupInfo; @@ -92,18 +95,15 @@ "inspector -> web seed table -> header tool tip")]; //prepare for animating peer table and web seed table - NSRect webSeedTableFrame = [[fWebSeedTable enclosingScrollView] frame]; - fWebSeedTableHeight = webSeedTableFrame.size.height; - fSpaceBetweenWebSeedAndPeer = webSeedTableFrame.origin.y - NSMaxY([[fPeerTable enclosingScrollView] frame]); + fViewTopMargin = fWebSeedTableTopConstraint.constant; CABasicAnimation * webSeedTableAnimation = [CABasicAnimation animation]; - webSeedTableAnimation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]; - webSeedTableAnimation.duration = 0.125; - [fWebSeedTableHeightConstraint setAnimations: [NSDictionary dictionaryWithObject: webSeedTableAnimation - forKey: @"constant"]]; - [fPeerTableTopConstraint setAnimations: [NSDictionary dictionaryWithObject: webSeedTableAnimation - forKey: @"constant"]]; - + [webSeedTableAnimation setTimingFunction: [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]]; + [webSeedTableAnimation setDuration: 0.125]; + [webSeedTableAnimation setDelegate: self]; + [webSeedTableAnimation setValue: WEB_SEED_ANIMATION_ID forKey: ANIMATION_ID_KEY]; + [fWebSeedTableTopConstraint setAnimations: @{ @"constant": webSeedTableAnimation }]; + [self setWebSeedTableHidden: YES animate: NO]; } @@ -450,6 +450,22 @@ return nil; } +- (void) animationDidStart: (CAAnimation *) animation +{ + if (![[animation valueForKey: ANIMATION_ID_KEY] isEqualToString: WEB_SEED_ANIMATION_ID]) + return; + + [[fWebSeedTable enclosingScrollView] setHidden: NO]; +} + +- (void) animationDidStop: (CAAnimation *) animation finished: (BOOL) finished +{ + if (![[animation valueForKey: ANIMATION_ID_KEY] isEqualToString: WEB_SEED_ANIMATION_ID]) + return; + + [[fWebSeedTable enclosingScrollView] setHidden: finished && fWebSeedTableTopConstraint.constant < 0]; +} + @end @implementation InfoPeersViewController (Private) @@ -495,13 +511,9 @@ if (animate && (![[self view] window] || ![[[self view] window] isVisible])) animate = NO; - const CGFloat webSeedTableHeight = hide ? 1 : fWebSeedTableHeight; - const CGFloat spaceBetweenWebSeedAndPeer = hide ? -2 : fSpaceBetweenWebSeedAndPeer; + const CGFloat webSeedTableTopMargin = hide ? -NSHeight([[fWebSeedTable enclosingScrollView] frame]) : fViewTopMargin; - [(animate ? [fWebSeedTableHeightConstraint animator] : fWebSeedTableHeightConstraint) setConstant: webSeedTableHeight]; - [(animate ? [fPeerTableTopConstraint animator] : fPeerTableTopConstraint) setConstant: spaceBetweenWebSeedAndPeer]; - - [[fWebSeedTable enclosingScrollView] setHidden: hide]; + [(animate ? [fWebSeedTableTopConstraint animator] : fWebSeedTableTopConstraint) setConstant: webSeedTableTopMargin]; } - (NSArray *) peerSortDescriptors