mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-19 12:49:02 +00:00
fixed problem with fetchData problem and updated nic cage example
This commit is contained in:
parent
a75871055f
commit
616e9ffbcb
@ -1,13 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#import "ASVideoNode.h"
|
#import "ASVideoNode.h"
|
||||||
#import "ASDisplayNodeInternal.h"
|
|
||||||
#import "ASDisplayNode+Subclasses.h"
|
|
||||||
#import "ASDisplayNode+FrameworkPrivate.h"
|
|
||||||
|
|
||||||
@interface ASDisplayNode ()
|
|
||||||
- (void)setInterfaceState:(ASInterfaceState)newState;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface ASVideoNode () {
|
@interface ASVideoNode () {
|
||||||
ASDN::RecursiveMutex _lock;
|
ASDN::RecursiveMutex _lock;
|
||||||
@ -24,13 +17,16 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface ASDisplayNode ()
|
||||||
|
- (void)setInterfaceState:(ASInterfaceState)newState;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation ASVideoNode
|
@implementation ASVideoNode
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
if (!(self = [super init])) { return nil; }
|
if (!(self = [super init])) { return nil; }
|
||||||
|
|
||||||
_playerNode = [[ASDisplayNode alloc] initWithLayerBlock:^CALayer *{ return [[AVPlayerLayer alloc] init]; }];
|
_playerNode = [[ASDisplayNode alloc] initWithLayerBlock:^CALayer *{ return [[AVPlayerLayer alloc] init]; }];
|
||||||
|
|
||||||
[self addSubnode:_playerNode];
|
[self addSubnode:_playerNode];
|
||||||
|
|
||||||
self.gravity = ASVideoGravityResizeAspect;
|
self.gravity = ASVideoGravityResizeAspect;
|
||||||
@ -124,18 +120,46 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_lock);
|
ASDN::MutexLocker l(_lock);
|
||||||
|
|
||||||
_currentItem = [[AVPlayerItem alloc] initWithAsset:_asset];
|
_currentItem = [[AVPlayerItem alloc] initWithAsset:_asset];
|
||||||
[_currentItem addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
|
[_currentItem addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
|
||||||
|
|
||||||
[((AVPlayerLayer *)_playerNode.layer).player replaceCurrentItemWithPlayerItem:_currentItem];
|
if (((AVPlayerLayer *)_playerNode.layer).player) {
|
||||||
}
|
[((AVPlayerLayer *)_playerNode.layer).player replaceCurrentItemWithPlayerItem:_currentItem];
|
||||||
|
} else {
|
||||||
|
((AVPlayerLayer *)_playerNode.layer).player = [[AVPlayer alloc] initWithPlayerItem:_currentItem];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if (_shouldAutoPlay) {
|
if (_shouldAutoPlay) {
|
||||||
[self play];
|
[self play];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- (void)fetchData
|
||||||
|
//{
|
||||||
|
// [super fetchData];
|
||||||
|
//
|
||||||
|
// @try {
|
||||||
|
// [_currentItem removeObserver:self forKeyPath:NSStringFromSelector(@selector(status))];
|
||||||
|
// }
|
||||||
|
// @catch (NSException * __unused exception) {
|
||||||
|
// NSLog(@"unnecessary removal in fetch data");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// ASDN::MutexLocker l(_lock);
|
||||||
|
//
|
||||||
|
// _currentItem = [[AVPlayerItem alloc] initWithAsset:_asset];
|
||||||
|
// [_currentItem addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
|
||||||
|
//
|
||||||
|
// [((AVPlayerLayer *)_playerNode.layer).player replaceCurrentItemWithPlayerItem:_currentItem];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (_shouldAutoPlay) {
|
||||||
|
// [self play];
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
- (void)clearFetchedData
|
- (void)clearFetchedData
|
||||||
{
|
{
|
||||||
[super clearFetchedData];
|
[super clearFetchedData];
|
||||||
@ -246,7 +270,7 @@
|
|||||||
|
|
||||||
- (void)pause;
|
- (void)pause;
|
||||||
{
|
{
|
||||||
// ASDN::MutexLocker l(_lock);
|
ASDN::MutexLocker l(_lock);
|
||||||
|
|
||||||
[[((AVPlayerLayer *)_playerNode.layer) player] pause];
|
[[((AVPlayerLayer *)_playerNode.layer) player] pause];
|
||||||
_shouldBePlaying = NO;
|
_shouldBePlaying = NO;
|
||||||
@ -265,3 +289,4 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -48,15 +48,8 @@ static NSString *kLinkAttributeName = @"PlaceKittenNodeLinkAttributeName";
|
|||||||
_textNode.linkAttributeNames = @[ kLinkAttributeName ];
|
_textNode.linkAttributeNames = @[ kLinkAttributeName ];
|
||||||
|
|
||||||
// generate an attributed string using the custom link attribute specified above
|
// generate an attributed string using the custom link attribute specified above
|
||||||
NSString *blurb = @"kittens courtesy placekitten.com \U0001F638";
|
NSString *blurb = @"Nic Cage courtesy of himself.";
|
||||||
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:blurb];
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:blurb];
|
||||||
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:16.0f] range:NSMakeRange(0, blurb.length)];
|
|
||||||
[string addAttributes:@{
|
|
||||||
kLinkAttributeName: [NSURL URLWithString:@"http://placekitten.com/"],
|
|
||||||
NSForegroundColorAttributeName: [UIColor grayColor],
|
|
||||||
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot),
|
|
||||||
}
|
|
||||||
range:[blurb rangeOfString:@"placekitten.com"]];
|
|
||||||
_textNode.attributedString = string;
|
_textNode.attributedString = string;
|
||||||
|
|
||||||
// add it as a subnode, and we're done
|
// add it as a subnode, and we're done
|
||||||
|
|||||||
@ -18,9 +18,9 @@
|
|||||||
#import "NicCageNode.h"
|
#import "NicCageNode.h"
|
||||||
|
|
||||||
|
|
||||||
static const NSInteger kLitterSize = 20; // intial number of kitten cells in ASTableView
|
static const NSInteger kCageSize = 20; // intial number of Cage cells in ASTableView
|
||||||
static const NSInteger kLitterBatchSize = 10; // number of kitten cells to add to ASTableView
|
static const NSInteger kCageBatchSize = 10; // number of Cage cells to add to ASTableView
|
||||||
static const NSInteger kMaxLitterSize = 100; // max number of kitten cells allowed in ASTableView
|
static const NSInteger kMaxCageSize = 100; // max number of Cage cells allowed in ASTableView
|
||||||
|
|
||||||
@interface ViewController () <ASTableViewDataSource, ASTableViewDelegate>
|
@interface ViewController () <ASTableViewDataSource, ASTableViewDelegate>
|
||||||
{
|
{
|
||||||
@ -55,11 +55,11 @@ static const NSInteger kMaxLitterSize = 100; // max number of kitten cell
|
|||||||
_tableView.asyncDelegate = self;
|
_tableView.asyncDelegate = self;
|
||||||
|
|
||||||
// populate our "data source" with some random kittens
|
// populate our "data source" with some random kittens
|
||||||
_kittenDataSource = [self createLitterWithSize:kLitterSize];
|
_kittenDataSource = [self createLitterWithSize:kCageSize];
|
||||||
|
|
||||||
_blurbNodeIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
|
_blurbNodeIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
|
||||||
|
|
||||||
self.title = @"Kittens";
|
self.title = @"Nic Cage";
|
||||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
|
||||||
target:self
|
target:self
|
||||||
action:@selector(toggleEditingMode)];
|
action:@selector(toggleEditingMode)];
|
||||||
@ -69,18 +69,16 @@ static const NSInteger kMaxLitterSize = 100; // max number of kitten cell
|
|||||||
|
|
||||||
- (NSMutableArray *)createLitterWithSize:(NSInteger)litterSize
|
- (NSMutableArray *)createLitterWithSize:(NSInteger)litterSize
|
||||||
{
|
{
|
||||||
NSMutableArray *kittens = [NSMutableArray arrayWithCapacity:litterSize];
|
NSMutableArray *cages = [NSMutableArray arrayWithCapacity:litterSize];
|
||||||
for (NSInteger i = 0; i < litterSize; i++) {
|
for (NSInteger i = 0; i < litterSize; i++) {
|
||||||
|
|
||||||
// placekitten.com will return the same kitten picture if the same pixel height & width are requested,
|
|
||||||
// so generate kittens with different width & height values.
|
|
||||||
u_int32_t deltaX = arc4random_uniform(10) - 5;
|
u_int32_t deltaX = arc4random_uniform(10) - 5;
|
||||||
u_int32_t deltaY = arc4random_uniform(10) - 5;
|
u_int32_t deltaY = arc4random_uniform(10) - 5;
|
||||||
CGSize size = CGSizeMake(350 + 2 * deltaX, 350 + 4 * deltaY);
|
CGSize size = CGSizeMake(350 + 2 * deltaX, 350 + 4 * deltaY);
|
||||||
|
|
||||||
[kittens addObject:[NSValue valueWithCGSize:size]];
|
[cages addObject:[NSValue valueWithCGSize:size]];
|
||||||
}
|
}
|
||||||
return kittens;
|
return cages;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setKittenDataSource:(NSMutableArray *)kittenDataSource {
|
- (void)setKittenDataSource:(NSMutableArray *)kittenDataSource {
|
||||||
@ -160,7 +158,7 @@ static const NSInteger kMaxLitterSize = 100; // max number of kitten cell
|
|||||||
|
|
||||||
- (BOOL)shouldBatchFetchForTableView:(UITableView *)tableView
|
- (BOOL)shouldBatchFetchForTableView:(UITableView *)tableView
|
||||||
{
|
{
|
||||||
return _kittenDataSource.count < kMaxLitterSize;
|
return _kittenDataSource.count < kMaxCageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tableView:(UITableView *)tableView willBeginBatchFetchWithContext:(ASBatchContext *)context
|
- (void)tableView:(UITableView *)tableView willBeginBatchFetchWithContext:(ASBatchContext *)context
|
||||||
@ -170,7 +168,7 @@ static const NSInteger kMaxLitterSize = 100; // max number of kitten cell
|
|||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
// populate a new array of random-sized kittens
|
// populate a new array of random-sized kittens
|
||||||
NSArray *moarKittens = [self createLitterWithSize:kLitterBatchSize];
|
NSArray *moarKittens = [self createLitterWithSize:kCageBatchSize];
|
||||||
|
|
||||||
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
|
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user