mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Some more changes
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#import "DetailRootNode.h"
|
||||
#import "SampleSizingNode.h"
|
||||
|
||||
@interface DetailViewController () <ASDisplayNodeSizingDelegate>
|
||||
@interface DetailViewController ()// <ASDisplayNodeSizingDelegate>
|
||||
@property (strong, nonatomic) SampleSizingNode *sizingNode;
|
||||
|
||||
@property (strong, nonatomic) ASNetworkImageNode *imageNode;
|
||||
@@ -40,7 +40,7 @@
|
||||
// Set the sizing delegate of the root node to the container
|
||||
_sizingNode = [SampleSizingNode new];
|
||||
_sizingNode.autoresizingMask = UIViewAutoresizingNone;
|
||||
_sizingNode.sizingDelegate = self;
|
||||
//_sizingNode.sizingDelegate = self;
|
||||
|
||||
_imageNode = [ASNetworkImageNode new];
|
||||
_imageNode.needsDisplayOnBoundsChange = YES;
|
||||
@@ -53,7 +53,7 @@
|
||||
[_buttonNode setTitle:@"Some Title" withFont:nil withColor:nil forState:ASControlStateNormal];
|
||||
[_buttonNode setTitle:@"Some Bla" withFont:nil withColor:[UIColor orangeColor] forState:ASControlStateHighlighted];
|
||||
[_buttonNode addTarget:self action:@selector(buttonAction:) forControlEvents:ASControlNodeEventTouchUpInside];
|
||||
_buttonNode.sizingDelegate = self;
|
||||
//_buttonNode.sizingDelegate = self;
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -74,7 +74,7 @@
|
||||
// Initial size of sizing node
|
||||
//self.sizingNode.frame = CGRectMake(100, 100, 50, 50);
|
||||
|
||||
[self displayNodeDidInvalidateSize:self.buttonNode];
|
||||
//[self displayNodeDidInvalidateSize:self.buttonNode];
|
||||
|
||||
// Initial size for image node
|
||||
// self.imageNode.frame = CGRectMake(50, 70, 100, 100);
|
||||
@@ -94,6 +94,7 @@
|
||||
{
|
||||
[super viewDidLayoutSubviews];
|
||||
|
||||
// Updat the sizing for the button node
|
||||
[self updateButtonNodeLayout];
|
||||
|
||||
// Update the sizing node layout
|
||||
@@ -116,23 +117,23 @@
|
||||
|
||||
// The sizing delegate will get callbacks if the size did invalidate of the display node. It's the job of the delegate
|
||||
// to get the new size from the display node and update the frame based on the returned size
|
||||
- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode
|
||||
{
|
||||
if (displayNode == self.buttonNode) {
|
||||
[self updateButtonNodeLayout];
|
||||
return;
|
||||
}
|
||||
|
||||
[self updateNodeLayout];
|
||||
|
||||
/*dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self updateNodeLayoutRandom];
|
||||
});*/
|
||||
|
||||
/*[NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
||||
[self updateNodeLayoutRandom];
|
||||
}];*/
|
||||
}
|
||||
//- (void)displayNodeDidInvalidateSize:(ASDisplayNode *)displayNode
|
||||
//{
|
||||
// if (displayNode == self.buttonNode) {
|
||||
// [self updateButtonNodeLayout];
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// [self updateNodeLayout];
|
||||
//
|
||||
// /*dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
// [self updateNodeLayoutRandom];
|
||||
// });*/
|
||||
//
|
||||
// /*[NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
||||
// [self updateNodeLayoutRandom];
|
||||
// }];*/
|
||||
//}
|
||||
|
||||
- (void)updateNodeLayout
|
||||
{
|
||||
@@ -140,29 +141,34 @@
|
||||
//return;
|
||||
// Use the bounds of the view and get the fitting size
|
||||
// This does not have any side effects, but can be called on the main thread without any problems
|
||||
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(CGFLOAT_MAX, 100.0)];
|
||||
CGSize size = [self.sizingNode sizeThatFits:CGSizeMake(INFINITY, 100.0)];
|
||||
//size.width -= 10;
|
||||
//[self.sizingNode setNeedsLayout];
|
||||
self.sizingNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
||||
(self.view.bounds.size.height - size.height) / 2.0,
|
||||
size.width, size.height);
|
||||
self.sizingNode.frame = CGRectMake((CGRectGetWidth(self.view.bounds) - size.width) / 2.0,
|
||||
(CGRectGetHeight(self.view.bounds) - size.height) / 2.0,
|
||||
size.width,
|
||||
size.height);
|
||||
|
||||
//dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
// Decrease the frame a bit
|
||||
self.sizingNode.frame = CGRectInset(self.sizingNode.frame, 10, 10);
|
||||
//});
|
||||
}
|
||||
|
||||
- (void)updateNodeLayoutRandom
|
||||
{
|
||||
CGRect bounds = self.view.bounds;
|
||||
|
||||
// Pick a randome width and height and set the frame of the node
|
||||
CGSize size = CGSizeZero;
|
||||
size.width = arc4random_uniform(self.view.bounds.size.width);
|
||||
size.height = arc4random_uniform(self.view.bounds.size.height);
|
||||
size.width = arc4random_uniform(CGRectGetWidth(bounds));
|
||||
size.height = arc4random_uniform(CGRectGetHeight(bounds));
|
||||
|
||||
//[self.sizingNode setNeedsLayout];
|
||||
self.sizingNode.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.0,
|
||||
(self.view.bounds.size.height - size.height) / 2.0,
|
||||
size.width, size.height);
|
||||
self.sizingNode.frame = CGRectMake((CGRectGetWidth(bounds) - size.width) / 2.0,
|
||||
(CGRectGetHeight(bounds) - size.height) / 2.0,
|
||||
size.width,
|
||||
size.height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,27 @@
|
||||
|
||||
#import "SampleSizingNode.h"
|
||||
|
||||
@interface SampleSizingNodeSubnode : ASDisplayNode
|
||||
@property (strong, nonatomic) ASTextNode *textNode;
|
||||
@end
|
||||
|
||||
@implementation SampleSizingNodeSubnode
|
||||
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
|
||||
// Manual layout after the normal layout engine did it's job
|
||||
// Calculated size can be used after the layout spec pass happened
|
||||
//self.textNode.frame = CGRectMake(self.textNode.frame.origin.x, self.textNode.frame.origin.y, self.textNode.calculatedSize.width, 20);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface SampleSizingNode ()
|
||||
@property (nonatomic, strong) ASDisplayNode *subnode;
|
||||
@property (nonatomic, assign) NSInteger state;
|
||||
|
||||
@property (nonatomic, strong) SampleSizingNodeSubnode *subnode;
|
||||
@property (nonatomic, strong) ASTextNode *textNode;
|
||||
@property (nonatomic, strong) ASNetworkImageNode *imageNode;
|
||||
@end
|
||||
@@ -35,13 +52,15 @@
|
||||
_imageNode.backgroundColor = [UIColor brownColor];
|
||||
_imageNode.needsDisplayOnBoundsChange = YES;
|
||||
_imageNode.style.height = ASDimensionMakeWithFraction(1.0);
|
||||
_imageNode.style.width = ASDimensionMake(30.0);
|
||||
_imageNode.style.width = ASDimensionMake(50.0);
|
||||
|
||||
|
||||
_subnode = [ASDisplayNode new];
|
||||
_subnode = [SampleSizingNodeSubnode new];
|
||||
_subnode.textNode = _textNode;
|
||||
_subnode.backgroundColor = [UIColor redColor];
|
||||
_subnode.automaticallyManagesSubnodes = YES;
|
||||
|
||||
// Layout description via layoutSpecBlock
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
_subnode.layoutSpecBlock = ^ASLayoutSpec *(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
|
||||
|
||||
@@ -113,7 +132,6 @@
|
||||
[self invalidateSize];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - ASDisplayNode
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
@@ -129,5 +147,13 @@
|
||||
child:self.subnode];
|
||||
}
|
||||
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
|
||||
// Layout after the official layout pass happened
|
||||
//self.subnode.frame = CGRectMake(self.subnode.frame.origin.x, self.subnode.frame.origin.y, 100, self.calculatedSize.height);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user