diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index c1c85898b..c2b87bd8d 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -148,6 +148,18 @@ var scaleYProperty = new dependencyObservable.Property( "View", new proxy.PropertyMetadata(1) ); + +var pivotXProperty = new dependencyObservable.Property( + "pivotX", + "View", + new proxy.PropertyMetadata(0.5) + ); + +var pivotYProperty = new dependencyObservable.Property( + "pivotY", + "View", + new proxy.PropertyMetadata(0.5) + ); var rotateProperty = new dependencyObservable.Property( "rotate", @@ -178,6 +190,8 @@ export class View extends proxy.ProxyObject implements definition.View { public static translateYProperty = translateYProperty; public static scaleXProperty = scaleXProperty; public static scaleYProperty = scaleYProperty; + public static pivotXProperty = pivotXProperty; + public static pivotYProperty = pivotYProperty; public static rotateProperty = rotateProperty; public static isEnabledProperty = isEnabledProperty; public static isUserInteractionEnabledProperty = isUserInteractionEnabledProperty; @@ -470,6 +484,20 @@ export class View extends proxy.ProxyObject implements definition.View { this._setValue(View.scaleYProperty, value); } + get pivotX(): number { + return this._getValue(View.pivotXProperty); + } + set pivotX(value: number) { + this._setValue(View.pivotXProperty, value); + } + + get pivotY(): number { + return this._getValue(View.pivotYProperty); + } + set pivotY(value: number) { + this._setValue(View.pivotYProperty, value); + } + get rotate(): number { return this._getValue(View.rotateProperty); } diff --git a/ui/core/view.android.ts b/ui/core/view.android.ts index 6a600229f..65b3a1fd0 100644 --- a/ui/core/view.android.ts +++ b/ui/core/view.android.ts @@ -44,6 +44,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData) } (viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged; +function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) { + var view = data.object; + var width = view._nativeView.getWidth(); + view._nativeView.setPivotX(data.newValue * width); +} +(viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged; + +function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) { + var view = data.object; + var height = view._nativeView.getHeight(); + view._nativeView.setPivotY(data.newValue * height); +} +(viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged; + function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) { var view = data.object; view._nativeView.setRotation(data.newValue); diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index a6fd21c06..9261fa2b9 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -259,6 +259,16 @@ declare module "ui/core/view" { */ scaleY: number; + /** + * Gets or sets the X component of the pivot point around which the view will be transformed. The deafault value is 0.5 representing the center of the view. + */ + pivotX: number; + + /** + * Gets or sets the Y component of the pivot point around which the view will be transformed. The deafault value is 0.5 representing the center of the view. + */ + pivotY: number; + /** * Gets or sets the rotate affine transform of the view. */ diff --git a/ui/core/view.ios.ts b/ui/core/view.ios.ts index 1927f8532..db586e7b7 100644 --- a/ui/core/view.ios.ts +++ b/ui/core/view.ios.ts @@ -66,6 +66,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData) } (viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged; +function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) { + var view = data.object; + var current = view._nativeView.layer.anchorPoint; + view._nativeView.layer.anchorPoint = CGPointMake(data.newValue, current.y); +} +(viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged; + +function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) { + var view = data.object; + var current = view._nativeView.layer.anchorPoint; + view._nativeView.layer.anchorPoint = CGPointMake(current.x, data.newValue); +} +(viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged; + function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) { var view = data.object; var newTransform = CGAffineTransformIdentity;