mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-13 01:40:12 +00:00
[tvOS] Added a default touch down animation for ASControlNode
This commit is contained in:
parent
4ad6d91a10
commit
d9cde1f08c
@ -30,6 +30,9 @@ typedef NS_OPTIONS(NSUInteger, ASControlNodeEvent)
|
||||
ASControlNodeEventTouchUpOutside = 1 << 5,
|
||||
/** A system event canceling the current touches for the control node. */
|
||||
ASControlNodeEventTouchCancel = 1 << 6,
|
||||
/** A system event when the Play/Pause button on the Apple TV remote is pressed. */
|
||||
ASControlNodeEventPrimaryActionTriggered = 1 << 13,
|
||||
|
||||
/** All events, including system events. */
|
||||
ASControlNodeEventAllEvents = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
@ -82,12 +82,21 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
|
||||
// As we have no targets yet, we start off with user interaction off. When a target is added, it'll get turned back on.
|
||||
self.userInteractionEnabled = NO;
|
||||
#if TARGET_OS_TV
|
||||
[self addTarget:self action:@selector(updateUI) forControlEvents:ASControlNodeEventAllEvents];
|
||||
#endif
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)didLoad
|
||||
{
|
||||
#if TARGET_OS_TV
|
||||
// [self addTarget:self action:@selector(updateUI) forControlEvents:ASControlNodeEventPrimaryActionTriggered];
|
||||
self.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressDown)];
|
||||
tapGestureRec.allowedPressTypes = @[@(UIPressTypeSelect)];
|
||||
[self.view addGestureRecognizer:tapGestureRec];
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - ASDisplayNode Overrides
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
@ -153,6 +162,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSLog(@"Touches Cancelled");
|
||||
// If we're not interested in touches, we have nothing to do.
|
||||
if (!self.enabled)
|
||||
return;
|
||||
@ -429,9 +439,17 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
}
|
||||
#if TARGET_OS_TV
|
||||
#pragma mark - tvOS
|
||||
- (void)updateUI
|
||||
- (void)pressDown
|
||||
{
|
||||
NSLog(@"Update UI");
|
||||
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveLinear animations:^{
|
||||
[self setPressedState];
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveLinear animations:^{
|
||||
[self setFocusedState];
|
||||
} completion:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)canBecomeFocused
|
||||
@ -446,33 +464,47 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
|
||||
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
|
||||
{
|
||||
NSLog(@"Focused");
|
||||
if (context.nextFocusedView && context.nextFocusedView == self.view) {
|
||||
//Focused
|
||||
[coordinator addCoordinatedAnimations:^{
|
||||
[self setFocusedState];
|
||||
} completion:nil];
|
||||
} else{
|
||||
//Not focused
|
||||
[coordinator addCoordinatedAnimations:^{
|
||||
[self setDefaultState];
|
||||
} completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setFocusedState
|
||||
{
|
||||
self.layer.shadowOffset = CGSizeMake(2, 10);
|
||||
self.layer.shadowColor = [UIColor blackColor].CGColor;
|
||||
self.layer.shadowRadius = 12.0;
|
||||
self.layer.shadowOpacity = 0.45;
|
||||
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.layer.bounds].CGPath;
|
||||
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
|
||||
} completion:^{
|
||||
}
|
||||
|
||||
}];
|
||||
} else{
|
||||
//Not focused
|
||||
[coordinator addCoordinatedAnimations:^{
|
||||
- (void)setPressedState
|
||||
{
|
||||
self.layer.shadowOffset = CGSizeMake(2, 2);
|
||||
self.layer.shadowColor = [UIColor blackColor].CGColor;
|
||||
self.layer.shadowRadius = 12.0;
|
||||
self.layer.shadowOpacity = 0.45;
|
||||
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.layer.bounds].CGPath;
|
||||
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
|
||||
}
|
||||
|
||||
- (void)setDefaultState
|
||||
{
|
||||
self.layer.shadowOffset = CGSizeZero;
|
||||
self.layer.shadowColor = [UIColor blackColor].CGColor;
|
||||
self.layer.shadowRadius = 0;
|
||||
self.layer.shadowOpacity = 0;
|
||||
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.layer.bounds].CGPath;
|
||||
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
|
||||
} completion:^{
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user