iOS:fix Slider and rotation

This commit is contained in:
pengfei.zhou 2020-04-07 10:58:44 +08:00 committed by osborn
parent 102f570fb4
commit f3c8d1be31
10 changed files with 17 additions and 45 deletions

View File

@ -161,6 +161,9 @@ - (void)layout {
} }
- (void)setFrame { - (void)setFrame {
if (!CGAffineTransformEqualToTransform(self.view.transform, CGAffineTransformIdentity)) {
return;
}
[self.view.subviews forEach:^(__kindof UIView *obj) { [self.view.subviews forEach:^(__kindof UIView *obj) {
[obj.doricLayout setFrame]; [obj.doricLayout setFrame];
}]; }];

View File

@ -21,15 +21,6 @@
// //
#import "DoricSlideItemNode.h" #import "DoricSlideItemNode.h"
@interface DoricSlideItemView : UIView
@end
@implementation DoricSlideItemView
- (void)layoutSubviews {
[super layoutSubviews];
}
@end
@implementation DoricSlideItemNode @implementation DoricSlideItemNode
- (instancetype)initWithContext:(DoricContext *)doricContext { - (instancetype)initWithContext:(DoricContext *)doricContext {
@ -45,7 +36,7 @@ - (void)initWithSuperNode:(DoricSuperNode *)superNode {
self.view.clipsToBounds = YES; self.view.clipsToBounds = YES;
} }
- (DoricSlideItemView *)build { - (void)requestLayout {
return [DoricSlideItemView new]; [self.view.doricLayout apply];
} }
@end @end

View File

@ -44,24 +44,6 @@ @interface DoricSliderView : UICollectionView
@end @end
@implementation DoricSliderView @implementation DoricSliderView
//- (CGSize)sizeThatFits:(CGSize)size {
// if (self.subviews.count > 0) {
// CGFloat width = size.width;
// CGFloat height = size.height;
// for (UIView *child in self.subviews) {
// CGSize childSize = [child measureSize:size];
// width = MAX(childSize.width, width);
// height = MAX(childSize.height, height);
// }
// return CGSizeMake(width, height);
// }
// return size;
//}
//
//- (void)layoutSelf:(CGSize)targetSize {
// [super layoutSelf:targetSize];
// [self reloadData];
//}
@end @end
@implementation DoricSliderNode @implementation DoricSliderNode
@ -138,13 +120,13 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection
DoricSlideItemNode *slideItemNode = [[DoricSlideItemNode alloc] initWithContext:self.doricContext]; DoricSlideItemNode *slideItemNode = [[DoricSlideItemNode alloc] initWithContext:self.doricContext];
[slideItemNode initWithSuperNode:self]; [slideItemNode initWithSuperNode:self];
cell.doricSlideItemNode = slideItemNode; cell.doricSlideItemNode = slideItemNode;
slideItemNode.view.width = collectionView.width;
slideItemNode.view.height = collectionView.height;
[cell.contentView addSubview:slideItemNode.view]; [cell.contentView addSubview:slideItemNode.view];
} }
DoricSlideItemNode *node = cell.doricSlideItemNode; DoricSlideItemNode *node = cell.doricSlideItemNode;
node.viewId = model[@"id"]; node.viewId = model[@"id"];
[node blend:props]; [node blend:props];
// CGSize size = [node.view measureSize:CGSizeMake(collectionView.width, collectionView.height)];
// [node.view layoutSelf:size];
return cell; return cell;
} }

View File

@ -137,8 +137,8 @@ - (void)blend:(NSDictionary *)props {
} }
[self blendView:self.view forPropName:key propValue:value]; [self blendView:self.view forPropName:key propValue:value];
} }
[self transformProperties];
[self afterBlended:props]; [self afterBlended:props];
[self transformProperties];
[self requestLayout]; [self requestLayout];
self.gradientLayer.frame = CGRectMake(0, 0, self.view.width, self.view.height); self.gradientLayer.frame = CGRectMake(0, 0, self.view.width, self.view.height);
} }
@ -157,14 +157,10 @@ - (void)transformProperties {
if (self.rotation) { if (self.rotation) {
transform = CGAffineTransformRotate(transform, (self.rotation.floatValue ?: 0) * M_PI); transform = CGAffineTransformRotate(transform, (self.rotation.floatValue ?: 0) * M_PI);
} }
if (self.pivotX || self.pivotY) { self.view.layer.anchorPoint = CGPointMake(self.pivotX.floatValue
self.view.layer.anchorPoint = CGPointMake(self.pivotX.floatValue ?: 0.5f, self.pivotY.floatValue ?: 0.5f);
?: 0.5f, self.pivotY.floatValue ?: 0.5f);
}
if (!CGAffineTransformEqualToTransform(transform, self.view.transform)) { if (!CGAffineTransformEqualToTransform(transform, self.view.transform)) {
dispatch_async(dispatch_get_main_queue(), ^{ self.view.transform = transform;
self.view.transform = transform;
});
} }
} }

View File

@ -2015,7 +2015,7 @@ function slider(config) {
} }
function slideItem(item, config) { function slideItem(item, config) {
return (new SlideItem).also(function (it) { return (new SlideItem).also(function (it) {
it.layoutConfig = layoutConfig().fit(); it.layoutConfig = layoutConfig().most();
if (item instanceof View) { if (item instanceof View) {
it.addChild(item); it.addChild(item);
} }

View File

@ -1512,7 +1512,7 @@ function slider(config) {
} }
function slideItem(item, config) { function slideItem(item, config) {
return (new SlideItem).also((it) => { return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().fit(); it.layoutConfig = layoutConfig().most();
if (item instanceof View) { if (item instanceof View) {
it.addChild(item); it.addChild(item);
} }

View File

@ -2971,7 +2971,7 @@ function slider(config) {
} }
function slideItem(item, config) { function slideItem(item, config) {
return (new SlideItem).also((it) => { return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().fit(); it.layoutConfig = layoutConfig().most();
if (item instanceof View) { if (item instanceof View) {
it.addChild(item); it.addChild(item);
} }

View File

@ -98,7 +98,7 @@ export function slider(config) {
} }
export function slideItem(item, config) { export function slideItem(item, config) {
return (new SlideItem).also((it) => { return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().fit(); it.layoutConfig = layoutConfig().most();
if (item instanceof View) { if (item instanceof View) {
it.addChild(item); it.addChild(item);
} }

View File

@ -105,7 +105,7 @@ export function slider(config: ISlider) {
export function slideItem(item: View | View[], config?: ISlideItem) { export function slideItem(item: View | View[], config?: ISlideItem) {
return (new SlideItem).also((it) => { return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().fit() it.layoutConfig = layoutConfig().most()
if (item instanceof View) { if (item instanceof View) {
it.addChild(item) it.addChild(item)
} else { } else {

View File

@ -3029,7 +3029,7 @@ function slider(config) {
} }
function slideItem(item, config) { function slideItem(item, config) {
return (new SlideItem).also((it) => { return (new SlideItem).also((it) => {
it.layoutConfig = layoutConfig().fit(); it.layoutConfig = layoutConfig().most();
if (item instanceof View) { if (item instanceof View) {
it.addChild(item); it.addChild(item);
} }