feat:step3:scrollview
This commit is contained in:
parent
af8a455d46
commit
1dabccbe50
@ -35,12 +35,16 @@ - (instancetype)init {
|
|||||||
|
|
||||||
- (CGSize)sizeThatFits:(CGSize)size {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
if (self.contentView) {
|
if (self.contentView) {
|
||||||
CGSize childSize = [self.contentView sizeThatFits:size];
|
return [self.contentView measureSize:size];
|
||||||
return CGSizeMake(MIN(size.width, childSize.width), MIN(size.height, childSize.height));
|
|
||||||
}
|
}
|
||||||
return CGSizeZero;
|
return CGSizeZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)layoutSelf:(CGSize)targetSize {
|
||||||
|
[super layoutSelf:targetSize];
|
||||||
|
[self.contentView layoutSelf:targetSize];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setContentView:(UIView *)contentView {
|
- (void)setContentView:(UIView *)contentView {
|
||||||
if (_contentView) {
|
if (_contentView) {
|
||||||
[_contentView removeFromSuperview];
|
[_contentView removeFromSuperview];
|
||||||
@ -58,9 +62,6 @@ - (void)setHeaderView:(UIView *)headerView {
|
|||||||
self.refreshable = YES;
|
self.refreshable = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)layoutSubviews {
|
|
||||||
[super layoutSubviews];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
|
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
|
||||||
if (-scrollView.contentOffset.y >= self.headerView.height) {
|
if (-scrollView.contentOffset.y >= self.headerView.height) {
|
||||||
|
@ -94,7 +94,7 @@ - (CGSize)measureSize:(CGSize)targetSize {
|
|||||||
* layout self and subviews
|
* layout self and subviews
|
||||||
* */
|
* */
|
||||||
- (void)layoutSelf:(CGSize)targetSize {
|
- (void)layoutSelf:(CGSize)targetSize {
|
||||||
CGSize contentSize = [self measureSize:targetSize];
|
CGSize contentSize = [self sizeThatFits:targetSize];
|
||||||
if (self.layoutConfig.widthSpec == DoricLayoutAtMost) {
|
if (self.layoutConfig.widthSpec == DoricLayoutAtMost) {
|
||||||
self.width = targetSize.width;
|
self.width = targetSize.width;
|
||||||
} else if (self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
} else if (self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||||
@ -108,8 +108,7 @@ - (void)layoutSelf:(CGSize)targetSize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)requestSuperview {
|
- (BOOL)requestSuperview {
|
||||||
return self.superview
|
return self.layoutConfig
|
||||||
&& self.layoutConfig
|
|
||||||
&& self.layoutConfig.widthSpec != DoricLayoutExact
|
&& self.layoutConfig.widthSpec != DoricLayoutExact
|
||||||
&& self.layoutConfig.heightSpec != DoricLayoutExact;
|
&& self.layoutConfig.heightSpec != DoricLayoutExact;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,11 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
|||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)layoutSelf:(CGSize)targetSize {
|
||||||
|
[super layoutSelf:targetSize];
|
||||||
|
[self reloadData];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,11 +34,16 @@ - (void)setContentView:(UIView *)contentView {
|
|||||||
|
|
||||||
- (CGSize)sizeThatFits:(CGSize)size {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
if (self.contentView) {
|
if (self.contentView) {
|
||||||
CGSize childSize = [self.contentView sizeThatFits:size];
|
return [self.contentView sizeThatFits:size];
|
||||||
return CGSizeMake(MIN(size.width, childSize.width), MIN(size.height, childSize.height));
|
|
||||||
}
|
}
|
||||||
return CGSizeZero;
|
return CGSizeZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)layoutSelf:(CGSize)targetSize {
|
||||||
|
[super layoutSelf:targetSize];
|
||||||
|
[self.contentView layoutSelf: [self.contentView sizeThatFits:targetSize]];
|
||||||
|
[self setContentSize:self.contentView.frame.size];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricScrollerNode ()
|
@interface DoricScrollerNode ()
|
||||||
|
Reference in New Issue
Block a user