mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[tvOS] Clean up and document parts of code.
This commit is contained in:
@@ -223,6 +223,43 @@
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (ASVerticalAlignment)contentVerticalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentVerticalAlignment;
|
||||
}
|
||||
|
||||
- (void)setContentVerticalAlignment:(ASVerticalAlignment)contentVerticalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentVerticalAlignment = contentVerticalAlignment;
|
||||
}
|
||||
|
||||
- (ASHorizontalAlignment)contentHorizontalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentHorizontalAlignment;
|
||||
}
|
||||
|
||||
- (void)setContentHorizontalAlignment:(ASHorizontalAlignment)contentHorizontalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentHorizontalAlignment = contentHorizontalAlignment;
|
||||
}
|
||||
|
||||
- (UIEdgeInsets)contentEdgeInsets
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentEdgeInsets;
|
||||
}
|
||||
|
||||
- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentEdgeInsets = contentEdgeInsets;
|
||||
}
|
||||
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(ASControlState)state
|
||||
{
|
||||
|
||||
@@ -1,469 +0,0 @@
|
||||
/* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import "ASButtonNode.h"
|
||||
#import "ASStackLayoutSpec.h"
|
||||
#import "ASThread.h"
|
||||
#import "ASDisplayNode+Subclasses.h"
|
||||
#import "ASBackgroundLayoutSpec.h"
|
||||
#import "ASInsetLayoutSpec.h"
|
||||
#import "ASDisplayNode+Beta.h"
|
||||
|
||||
@interface ASButtonNode ()
|
||||
{
|
||||
ASDN::RecursiveMutex _propertyLock;
|
||||
|
||||
NSAttributedString *_normalAttributedTitle;
|
||||
NSAttributedString *_highlightedAttributedTitle;
|
||||
NSAttributedString *_selectedAttributedTitle;
|
||||
NSAttributedString *_disabledAttributedTitle;
|
||||
|
||||
UIImage *_normalImage;
|
||||
UIImage *_highlightedImage;
|
||||
UIImage *_selectedImage;
|
||||
UIImage *_disabledImage;
|
||||
|
||||
UIImage *_normalBackgroundImage;
|
||||
UIImage *_highlightedBackgroundImage;
|
||||
UIImage *_selectedBackgroundImage;
|
||||
UIImage *_disabledBackgroundImage;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ASButtonNode
|
||||
|
||||
@synthesize contentSpacing = _contentSpacing;
|
||||
@synthesize laysOutHorizontally = _laysOutHorizontally;
|
||||
@synthesize contentVerticalAlignment = _contentVerticalAlignment;
|
||||
@synthesize contentHorizontalAlignment = _contentHorizontalAlignment;
|
||||
@synthesize contentEdgeInsets = _contentEdgeInsets;
|
||||
@synthesize titleNode = _titleNode;
|
||||
@synthesize imageNode = _imageNode;
|
||||
@synthesize backgroundImageNode = _backgroundImageNode;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.usesImplicitHierarchyManagement = YES;
|
||||
|
||||
_contentSpacing = 8.0;
|
||||
_laysOutHorizontally = YES;
|
||||
_contentHorizontalAlignment = ASAlignmentMiddle;
|
||||
_contentVerticalAlignment = ASAlignmentCenter;
|
||||
_contentEdgeInsets = UIEdgeInsetsZero;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (ASTextNode *)titleNode
|
||||
{
|
||||
if (!_titleNode) {
|
||||
_titleNode = [[ASTextNode alloc] init];
|
||||
[_titleNode setLayerBacked:YES];
|
||||
}
|
||||
return _titleNode;
|
||||
}
|
||||
|
||||
- (ASImageNode *)imageNode
|
||||
{
|
||||
if (!_imageNode) {
|
||||
_imageNode = [[ASImageNode alloc] init];
|
||||
[_imageNode setLayerBacked:YES];
|
||||
[_titleNode setFlexShrink:YES];
|
||||
}
|
||||
return _imageNode;
|
||||
}
|
||||
|
||||
- (ASImageNode *)backgroundImageNode
|
||||
{
|
||||
if (!_backgroundImageNode) {
|
||||
_backgroundImageNode = [[ASImageNode alloc] init];
|
||||
[_backgroundImageNode setLayerBacked:YES];
|
||||
[_backgroundImageNode setContentMode:UIViewContentModeScaleToFill];
|
||||
}
|
||||
return _backgroundImageNode;
|
||||
}
|
||||
|
||||
- (void)setLayerBacked:(BOOL)layerBacked
|
||||
{
|
||||
ASDisplayNodeAssert(!layerBacked, @"ASButtonNode must not be layer backed!");
|
||||
[super setLayerBacked:layerBacked];
|
||||
}
|
||||
|
||||
- (void)setEnabled:(BOOL)enabled
|
||||
{
|
||||
[super setEnabled:enabled];
|
||||
[self updateButtonContent];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted
|
||||
{
|
||||
[super setHighlighted:highlighted];
|
||||
[self updateButtonContent];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected
|
||||
{
|
||||
[super setSelected:selected];
|
||||
[self updateButtonContent];
|
||||
}
|
||||
|
||||
- (void)updateButtonContent
|
||||
{
|
||||
[self updateBackgroundImage];
|
||||
[self updateImage];
|
||||
[self updateTitle];
|
||||
}
|
||||
|
||||
- (void)setDisplaysAsynchronously:(BOOL)displaysAsynchronously
|
||||
{
|
||||
[super setDisplaysAsynchronously:displaysAsynchronously];
|
||||
[self.backgroundImageNode setDisplaysAsynchronously:displaysAsynchronously];
|
||||
[self.imageNode setDisplaysAsynchronously:displaysAsynchronously];
|
||||
[self.titleNode setDisplaysAsynchronously:displaysAsynchronously];
|
||||
}
|
||||
|
||||
- (void)updateImage
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
|
||||
UIImage *newImage;
|
||||
if (self.enabled == NO && _disabledImage) {
|
||||
newImage = _disabledImage;
|
||||
} else if (self.highlighted && _highlightedImage) {
|
||||
newImage = _highlightedImage;
|
||||
} else if (self.selected && _selectedImage) {
|
||||
newImage = _selectedImage;
|
||||
} else {
|
||||
newImage = _normalImage;
|
||||
}
|
||||
|
||||
if ((_imageNode != nil || newImage != nil) && newImage != self.imageNode.image) {
|
||||
_imageNode.image = newImage;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTitle
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
NSAttributedString *newTitle;
|
||||
if (self.enabled == NO && _disabledAttributedTitle) {
|
||||
newTitle = _disabledAttributedTitle;
|
||||
} else if (self.highlighted && _highlightedAttributedTitle) {
|
||||
newTitle = _highlightedAttributedTitle;
|
||||
} else if (self.selected && _selectedAttributedTitle) {
|
||||
newTitle = _selectedAttributedTitle;
|
||||
} else {
|
||||
newTitle = _normalAttributedTitle;
|
||||
}
|
||||
|
||||
if ((_titleNode != nil || newTitle.length > 0) && newTitle != self.titleNode.attributedString) {
|
||||
_titleNode.attributedString = newTitle;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateBackgroundImage
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
|
||||
UIImage *newImage;
|
||||
if (self.enabled == NO && _disabledBackgroundImage) {
|
||||
newImage = _disabledBackgroundImage;
|
||||
} else if (self.highlighted && _highlightedBackgroundImage) {
|
||||
newImage = _highlightedBackgroundImage;
|
||||
} else if (self.selected && _selectedBackgroundImage) {
|
||||
newImage = _selectedBackgroundImage;
|
||||
} else {
|
||||
newImage = _normalBackgroundImage;
|
||||
}
|
||||
|
||||
if ((_backgroundImageNode != nil || newImage != nil) && newImage != self.backgroundImageNode.image) {
|
||||
_backgroundImageNode.image = newImage;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)contentSpacing
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentSpacing;
|
||||
}
|
||||
|
||||
- (void)setContentSpacing:(CGFloat)contentSpacing
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
if (contentSpacing == _contentSpacing)
|
||||
return;
|
||||
|
||||
_contentSpacing = contentSpacing;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (BOOL)laysOutHorizontally
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _laysOutHorizontally;
|
||||
}
|
||||
|
||||
- (void)setLaysOutHorizontally:(BOOL)laysOutHorizontally
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
if (laysOutHorizontally == _laysOutHorizontally)
|
||||
return;
|
||||
|
||||
_laysOutHorizontally = laysOutHorizontally;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
#if TARGET_OS_IOS
|
||||
=======
|
||||
- (ASVerticalAlignment)contentVerticalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentVerticalAlignment;
|
||||
}
|
||||
|
||||
- (void)setContentVerticalAlignment:(ASVerticalAlignment)contentVerticalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentVerticalAlignment = contentVerticalAlignment;
|
||||
}
|
||||
|
||||
- (ASHorizontalAlignment)contentHorizontalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentHorizontalAlignment;
|
||||
}
|
||||
|
||||
- (void)setContentHorizontalAlignment:(ASHorizontalAlignment)contentHorizontalAlignment
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentHorizontalAlignment = contentHorizontalAlignment;
|
||||
}
|
||||
|
||||
- (UIEdgeInsets)contentEdgeInsets
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
return _contentEdgeInsets;
|
||||
}
|
||||
|
||||
- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
_contentEdgeInsets = contentEdgeInsets;
|
||||
}
|
||||
|
||||
>>>>>>> upstream/master
|
||||
- (void)setTitle:(NSString *)title withFont:(UIFont *)font withColor:(UIColor *)color forState:(ASControlState)state
|
||||
{
|
||||
NSDictionary *attributes = @{
|
||||
NSFontAttributeName: font ? font :[UIFont systemFontOfSize:[UIFont buttonFontSize]],
|
||||
NSForegroundColorAttributeName : color ? color : [UIColor blackColor]
|
||||
};
|
||||
|
||||
NSAttributedString *string = [[NSAttributedString alloc] initWithString:title
|
||||
attributes:attributes];
|
||||
[self setAttributedTitle:string forState:state];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (NSAttributedString *)attributedTitleForState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
return _normalAttributedTitle;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
return _highlightedAttributedTitle;
|
||||
|
||||
case ASControlStateSelected:
|
||||
return _selectedAttributedTitle;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
return _disabledAttributedTitle;
|
||||
|
||||
default:
|
||||
return _normalAttributedTitle;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAttributedTitle:(NSAttributedString *)title forState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
_normalAttributedTitle = [title copy];
|
||||
break;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
_highlightedAttributedTitle = [title copy];
|
||||
break;
|
||||
|
||||
case ASControlStateSelected:
|
||||
_selectedAttributedTitle = [title copy];
|
||||
break;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
_disabledAttributedTitle = [title copy];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[self updateTitle];
|
||||
}
|
||||
|
||||
- (UIImage *)imageForState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
return _normalImage;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
return _highlightedImage;
|
||||
|
||||
case ASControlStateSelected:
|
||||
return _selectedImage;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
return _disabledImage;
|
||||
|
||||
default:
|
||||
return _normalImage;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setImage:(UIImage *)image forState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
_normalImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
_highlightedImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateSelected:
|
||||
_selectedImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
_disabledImage = image;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[self updateImage];
|
||||
}
|
||||
|
||||
- (void)setBackgroundImage:(UIImage *)image forState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
_normalBackgroundImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
_highlightedBackgroundImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateSelected:
|
||||
_selectedBackgroundImage = image;
|
||||
break;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
_disabledBackgroundImage = image;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[self updateBackgroundImage];
|
||||
}
|
||||
|
||||
- (UIImage *)backgroundImageForState:(ASControlState)state
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
switch (state) {
|
||||
case ASControlStateNormal:
|
||||
return _normalBackgroundImage;
|
||||
|
||||
case ASControlStateHighlighted:
|
||||
return _highlightedBackgroundImage;
|
||||
|
||||
case ASControlStateSelected:
|
||||
return _selectedBackgroundImage;
|
||||
|
||||
case ASControlStateDisabled:
|
||||
return _disabledBackgroundImage;
|
||||
|
||||
default:
|
||||
return _normalBackgroundImage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
UIEdgeInsets contentEdgeInsets;
|
||||
ASLayoutSpec *spec;
|
||||
ASStackLayoutSpec *stack = [[ASStackLayoutSpec alloc] init];
|
||||
{
|
||||
ASDN::MutexLocker l(_propertyLock);
|
||||
stack.direction = _laysOutHorizontally ? ASStackLayoutDirectionHorizontal : ASStackLayoutDirectionVertical;
|
||||
stack.spacing = _contentSpacing;
|
||||
stack.horizontalAlignment = _contentHorizontalAlignment;
|
||||
stack.verticalAlignment = _contentVerticalAlignment;
|
||||
|
||||
contentEdgeInsets = _contentEdgeInsets;
|
||||
}
|
||||
|
||||
NSMutableArray *children = [[NSMutableArray alloc] initWithCapacity:2];
|
||||
if (_imageNode.image) {
|
||||
[children addObject:_imageNode];
|
||||
}
|
||||
|
||||
if (_titleNode.attributedString.length > 0) {
|
||||
[children addObject:_titleNode];
|
||||
}
|
||||
|
||||
stack.children = children;
|
||||
|
||||
spec = stack;
|
||||
|
||||
if (UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, contentEdgeInsets) == NO) {
|
||||
spec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:contentEdgeInsets child:spec];
|
||||
}
|
||||
|
||||
if (_backgroundImageNode.image) {
|
||||
spec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:spec
|
||||
background:_backgroundImageNode];
|
||||
}
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
_backgroundImageNode.hidden = (_backgroundImageNode.image == nil);
|
||||
_imageNode.hidden = (_imageNode.image == nil);
|
||||
_titleNode.hidden = (_titleNode.attributedString.length == 0);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -89,7 +89,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
- (void)didLoad
|
||||
{
|
||||
#if TARGET_OS_TV
|
||||
// [self addTarget:self action:@selector(updateUI) forControlEvents:ASControlNodeEventPrimaryActionTriggered];
|
||||
//On tvOS all control views, such as buttons, interact with the focus system even if they don't have a target set on them. Here we add our own internal tap gesture to handle this behaviour.
|
||||
self.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressDown)];
|
||||
tapGestureRec.allowedPressTypes = @[@(UIPressTypeSelect)];
|
||||
@@ -162,7 +162,6 @@ 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;
|
||||
@@ -464,6 +463,7 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
|
||||
|
||||
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
|
||||
{
|
||||
//FIXME: This is never valid inside an ASCellNode
|
||||
if (context.nextFocusedView && context.nextFocusedView == self.view) {
|
||||
//Focused
|
||||
[coordinator addCoordinatedAnimations:^{
|
||||
|
||||
@@ -421,11 +421,14 @@
|
||||
{
|
||||
[super touchesBegan:touches withEvent:event];
|
||||
isDefaultState = NO;
|
||||
UIView *view = [self getView];
|
||||
CALayer *layer = view.layer;
|
||||
|
||||
CGSize targetShadowOffset = CGSizeMake(0.0, self.bounds.size.height/8);
|
||||
[self.layer removeAllAnimations];
|
||||
[layer removeAllAnimations];
|
||||
[CATransaction begin];
|
||||
[CATransaction setCompletionBlock:^{
|
||||
self.layer.shadowOffset = targetShadowOffset;
|
||||
layer.shadowOffset = targetShadowOffset;
|
||||
}];
|
||||
|
||||
CABasicAnimation *shadowOffsetAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];
|
||||
@@ -434,7 +437,7 @@
|
||||
shadowOffsetAnimation.removedOnCompletion = NO;
|
||||
shadowOffsetAnimation.fillMode = kCAFillModeForwards;
|
||||
shadowOffsetAnimation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeOut"];
|
||||
[self.layer addAnimation:shadowOffsetAnimation forKey:@"shadowOffset"];
|
||||
[layer addAnimation:shadowOffsetAnimation forKey:@"shadowOffset"];
|
||||
[CATransaction commit];
|
||||
|
||||
CABasicAnimation *shadowOpacityAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
|
||||
@@ -443,29 +446,35 @@
|
||||
shadowOpacityAnimation.removedOnCompletion = false;
|
||||
shadowOpacityAnimation.fillMode = kCAFillModeForwards;
|
||||
shadowOpacityAnimation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeOut"];
|
||||
[self.layer addAnimation:shadowOpacityAnimation forKey:@"shadowOpacityAnimation"];
|
||||
[layer addAnimation:shadowOpacityAnimation forKey:@"shadowOpacityAnimation"];
|
||||
|
||||
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.25, 1.25);
|
||||
view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.25, 1.25);
|
||||
|
||||
[CATransaction commit];
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
[super touchesMoved:touches withEvent:event];
|
||||
|
||||
if (!isDefaultState) {
|
||||
UIView *view = [self getView];
|
||||
|
||||
UITouch *touch = [touches anyObject];
|
||||
// Get the specific point that was touched
|
||||
// This is quite messy in it's current state so is not ready for production. The reason it is here is for others to contribute and to make it clear what is occuring.
|
||||
// TODO: Clean up, and improve visuals.
|
||||
CGPoint point = [touch locationInView:self.view];
|
||||
float tilt = 0;
|
||||
float pitch = 0;
|
||||
float yaw = 0;
|
||||
BOOL topHalf = NO;
|
||||
if (point.y > CGRectGetHeight(self.view.frame)) {
|
||||
tilt = 15;
|
||||
pitch = 15;
|
||||
} else if (point.y < -CGRectGetHeight(self.view.frame)) {
|
||||
tilt = -15;
|
||||
pitch = -15;
|
||||
} else {
|
||||
tilt = (point.y/CGRectGetHeight(self.view.frame))*15;
|
||||
pitch = (point.y/CGRectGetHeight(self.view.frame))*15;
|
||||
}
|
||||
if (tilt < 0) {
|
||||
if (pitch < 0) {
|
||||
topHalf = YES;
|
||||
}
|
||||
|
||||
@@ -484,13 +493,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
CATransform3D tiltTransform = CATransform3DMakeRotation([self degressToRadians:tilt],1.0,0.0,0.0);
|
||||
CATransform3D pitchTransform = CATransform3DMakeRotation([self degressToRadians:pitch],1.0,0.0,0.0);
|
||||
CATransform3D yawTransform = CATransform3DMakeRotation([self degressToRadians:yaw],0.0,1.0,0.0);
|
||||
CATransform3D transform = CATransform3DConcat(tiltTransform, yawTransform);
|
||||
CATransform3D transform = CATransform3DConcat(pitchTransform, yawTransform);
|
||||
CATransform3D scaleAndTransform = CATransform3DConcat(transform, CATransform3DMakeAffineTransform(CGAffineTransformScale(CGAffineTransformIdentity, 1.25, 1.25)));
|
||||
|
||||
[UIView animateWithDuration:0.5 animations:^{
|
||||
self.view.layer.transform = scaleAndTransform;
|
||||
view.layer.transform = scaleAndTransform;
|
||||
}];
|
||||
} else {
|
||||
[self setDefaultState];
|
||||
@@ -500,26 +509,30 @@
|
||||
|
||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[super touchesEnded:touches withEvent:event];
|
||||
[self finishTouches];
|
||||
}
|
||||
|
||||
- (void)finishTouches
|
||||
{
|
||||
if (!isDefaultState) {
|
||||
UIView *view = [self getView];
|
||||
CALayer *layer = view.layer;
|
||||
|
||||
CGSize targetShadowOffset = CGSizeMake(0.0, self.bounds.size.height/8);
|
||||
CATransform3D targetScaleTransform = CATransform3DMakeScale(1.2, 1.2, 1.2);
|
||||
[CATransaction begin];
|
||||
[CATransaction setCompletionBlock:^{
|
||||
self.layer.shadowOffset = targetShadowOffset;
|
||||
layer.shadowOffset = targetShadowOffset;
|
||||
}];
|
||||
[CATransaction commit];
|
||||
|
||||
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||||
self.view.layer.transform = targetScaleTransform;
|
||||
view.layer.transform = targetScaleTransform;
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
[self.layer removeAnimationForKey:@"shadowOffset"];
|
||||
[self.layer removeAnimationForKey:@"shadowOpacity"];
|
||||
[layer removeAnimationForKey:@"shadowOffset"];
|
||||
[layer removeAnimationForKey:@"shadowOpacity"];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
@@ -529,26 +542,39 @@
|
||||
|
||||
- (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.25, 1.25);
|
||||
UIView *view = [self getView];
|
||||
CALayer *layer = view.layer;
|
||||
layer.shadowOffset = CGSizeMake(2, 10);
|
||||
layer.shadowColor = [UIColor blackColor].CGColor;
|
||||
layer.shadowRadius = 12.0;
|
||||
layer.shadowOpacity = 0.45;
|
||||
layer.shadowPath = [UIBezierPath bezierPathWithRect:self.layer.bounds].CGPath;
|
||||
view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.25, 1.25);
|
||||
}
|
||||
|
||||
- (void)setDefaultState
|
||||
{
|
||||
self.view.transform = CGAffineTransformIdentity;
|
||||
self.layer.shadowOpacity = 0;
|
||||
self.layer.shadowOffset = CGSizeZero;
|
||||
self.layer.shadowRadius = 0;
|
||||
self.layer.shadowPath = nil;
|
||||
[self.layer removeAnimationForKey:@"shadowOffset"];
|
||||
[self.layer removeAnimationForKey:@"shadowOpacity"];
|
||||
UIView *view = [self getView];
|
||||
CALayer *layer = view.layer;
|
||||
view.transform = CGAffineTransformIdentity;
|
||||
layer.shadowOpacity = 0;
|
||||
layer.shadowOffset = CGSizeZero;
|
||||
layer.shadowRadius = 0;
|
||||
layer.shadowPath = nil;
|
||||
[layer removeAnimationForKey:@"shadowOffset"];
|
||||
[layer removeAnimationForKey:@"shadowOpacity"];
|
||||
isDefaultState = YES;
|
||||
}
|
||||
|
||||
- (UIView *)getView
|
||||
{
|
||||
UIView *view = self.view;
|
||||
//If we are inside a ASCellNode, then we need to apply our focus effects to the ASCellNode view/layer rather than the ASImageNode view/layer.
|
||||
if (CGSizeEqualToSize(self.view.superview.frame.size, self.view.frame.size) && self.view.superview.superview) {
|
||||
view = self.view.superview.superview;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
- (float)degressToRadians:(float)value
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user