You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by so...@apache.org on 2017/03/17 07:11:36 UTC

[32/40] incubator-weex git commit: * [ios] fix animation about bounds

* [ios] fix animation about bounds


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/21242dbd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/21242dbd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/21242dbd

Branch: refs/heads/0.12-dev
Commit: 21242dbd0d333ea3011d542c5e726bdaf6a438ce
Parents: 374361f
Author: acton393 <zh...@gmail.com>
Authored: Thu Mar 16 19:18:36 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Mar 16 19:18:36 2017 +0800

----------------------------------------------------------------------
 .../WeexSDK/Sources/Module/WXAnimationModule.m  | 43 +++++++++++++++-----
 1 file changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/21242dbd/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
index 6cd4ad9..94ec6f0 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
@@ -23,6 +23,7 @@
 @property (nonatomic, assign) double duration;
 @property (nonatomic, assign) double delay;
 @property (nonatomic, strong) CAMediaTimingFunction *timingFunction;
+@property (nonatomic, assign) CGPoint originAnchorPoint;
 
 @end
 
@@ -84,11 +85,14 @@
         _animationInfo.target.view.layer.backgroundColor = (__bridge CGColorRef _Nullable)(_animationInfo.toValue);
     } else if ([_animationInfo.propertyName isEqualToString:@"opacity"]) {
         _animationInfo.target.view.layer.opacity = [_animationInfo.toValue floatValue];
-    } else if ([_animationInfo.propertyName isEqualToString:@"bounds"]) {
-        //set the layer bounds
-        if(strcmp([_animationInfo.toValue objCType], @encode(CGRect)) == 0) {
-            _animationInfo.target.view.layer.bounds = [_animationInfo.toValue CGRectValue];
+    } else if ([_animationInfo.propertyName hasPrefix:@"bounds.size"]) {
+        CGRect newBounds = _animationInfo.target.view.layer.bounds;
+        if ([_animationInfo.propertyName isEqualToString:@"bounds.size.width"]) {
+            newBounds.size = CGSizeMake([_animationInfo.toValue floatValue], newBounds.size.height);
+        }else if ([_animationInfo.propertyName isEqualToString:@"bounds.size.height"]) {
+            newBounds.size = CGSizeMake(newBounds.size.width,[_animationInfo.toValue floatValue]);
         }
+        _animationInfo.target.view.layer.bounds = newBounds;
     }
 }
 
@@ -98,6 +102,15 @@
         return;
     }
     
+    if ([_animationInfo.propertyName hasPrefix:@"bounds.size"]) {
+        /*
+         * http://ronnqvi.st/about-the-anchorpoint/
+         */
+        //
+        CGRect originFrame = _animationInfo.target.view.layer.frame;
+        _animationInfo.target.view.layer.anchorPoint = _animationInfo.originAnchorPoint;
+        _animationInfo.target.view.layer.frame = originFrame;
+    }
     [_animationInfo.target.layer removeAllAnimations];
     
     if (_finishBlock) {
@@ -212,18 +225,18 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
             info.toValue = @([value floatValue]);
             [infos addObject:info];
         } else if ([property isEqualToString:@"width"]) {
-            info.propertyName = @"bounds";
-            info.fromValue = [NSValue valueWithCGRect:layer.bounds];
+            info.propertyName = @"bounds.size.width";
+            info.fromValue = @(layer.bounds.size.width);
             CGRect newBounds = layer.bounds;
             newBounds.size = CGSizeMake([WXConvert WXPixelType:value scaleFactor:self.weexInstance.pixelScaleFactor], newBounds.size.height);
-            info.toValue = [NSValue valueWithCGRect:newBounds];
+            info.toValue = @(newBounds.size.width);
             [infos addObject:info];
         } else if ([property isEqualToString:@"height"]) {
-            info.propertyName = @"bounds";
-            info.fromValue = [NSValue valueWithCGRect:layer.bounds];
+            info.propertyName = @"bounds.size.height";
+            info.fromValue = @(layer.bounds.size.height);
             CGRect newBounds = layer.bounds;
             newBounds.size = CGSizeMake(newBounds.size.width, [WXConvert WXPixelType:value scaleFactor:self.weexInstance.pixelScaleFactor]);
-            info.toValue = [NSValue valueWithCGRect:newBounds];
+            info.toValue = @(newBounds.size.height);
             [infos addObject:info];
         }
     }
@@ -271,6 +284,16 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
     animation.delegate = delegate;
     
     CALayer *layer = info.target.layer;
+    if ([info.propertyName hasPrefix:@"bounds"]) {
+        info.originAnchorPoint = layer.anchorPoint;
+        CGRect originFrame = layer.frame;
+         /*
+          * if anchorPoint changed, the origin of layer's frame will change
+          * http://ronnqvi.st/about-the-anchorpoint/
+         */
+        layer.anchorPoint = CGPointZero;
+        layer.frame = originFrame;
+    }
     [layer addAnimation:animation forKey:info.propertyName];
 }