mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Pivot point implementation
This commit is contained in:
@@ -149,6 +149,18 @@ var scaleYProperty = new dependencyObservable.Property(
|
|||||||
new proxy.PropertyMetadata(1)
|
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(
|
var rotateProperty = new dependencyObservable.Property(
|
||||||
"rotate",
|
"rotate",
|
||||||
"View",
|
"View",
|
||||||
@@ -178,6 +190,8 @@ export class View extends proxy.ProxyObject implements definition.View {
|
|||||||
public static translateYProperty = translateYProperty;
|
public static translateYProperty = translateYProperty;
|
||||||
public static scaleXProperty = scaleXProperty;
|
public static scaleXProperty = scaleXProperty;
|
||||||
public static scaleYProperty = scaleYProperty;
|
public static scaleYProperty = scaleYProperty;
|
||||||
|
public static pivotXProperty = pivotXProperty;
|
||||||
|
public static pivotYProperty = pivotYProperty;
|
||||||
public static rotateProperty = rotateProperty;
|
public static rotateProperty = rotateProperty;
|
||||||
public static isEnabledProperty = isEnabledProperty;
|
public static isEnabledProperty = isEnabledProperty;
|
||||||
public static isUserInteractionEnabledProperty = isUserInteractionEnabledProperty;
|
public static isUserInteractionEnabledProperty = isUserInteractionEnabledProperty;
|
||||||
@@ -470,6 +484,20 @@ export class View extends proxy.ProxyObject implements definition.View {
|
|||||||
this._setValue(View.scaleYProperty, value);
|
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 {
|
get rotate(): number {
|
||||||
return this._getValue(View.rotateProperty);
|
return this._getValue(View.rotateProperty);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData)
|
|||||||
}
|
}
|
||||||
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
|
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
|
||||||
|
|
||||||
|
function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var view = <View>data.object;
|
||||||
|
var width = view._nativeView.getWidth();
|
||||||
|
view._nativeView.setPivotX(data.newValue * width);
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged;
|
||||||
|
|
||||||
|
function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var view = <View>data.object;
|
||||||
|
var height = view._nativeView.getHeight();
|
||||||
|
view._nativeView.setPivotY(data.newValue * height);
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged;
|
||||||
|
|
||||||
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var view = <View>data.object;
|
var view = <View>data.object;
|
||||||
view._nativeView.setRotation(data.newValue);
|
view._nativeView.setRotation(data.newValue);
|
||||||
|
|||||||
10
ui/core/view.d.ts
vendored
10
ui/core/view.d.ts
vendored
@@ -259,6 +259,16 @@ declare module "ui/core/view" {
|
|||||||
*/
|
*/
|
||||||
scaleY: number;
|
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.
|
* Gets or sets the rotate affine transform of the view.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -66,6 +66,20 @@ function onScaleYPropertyChanged(data: dependencyObservable.PropertyChangeData)
|
|||||||
}
|
}
|
||||||
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
|
(<proxy.PropertyMetadata>viewCommon.View.scaleYProperty.metadata).onSetNativeValue = onScaleYPropertyChanged;
|
||||||
|
|
||||||
|
function onPivotXPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var view = <View>data.object;
|
||||||
|
var current = view._nativeView.layer.anchorPoint;
|
||||||
|
view._nativeView.layer.anchorPoint = CGPointMake(data.newValue, current.y);
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>viewCommon.View.pivotXProperty.metadata).onSetNativeValue = onPivotXPropertyChanged;
|
||||||
|
|
||||||
|
function onPivotYPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var view = <View>data.object;
|
||||||
|
var current = view._nativeView.layer.anchorPoint;
|
||||||
|
view._nativeView.layer.anchorPoint = CGPointMake(current.x, data.newValue);
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>viewCommon.View.pivotYProperty.metadata).onSetNativeValue = onPivotYPropertyChanged;
|
||||||
|
|
||||||
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onRotatePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
var view = <View>data.object;
|
var view = <View>data.object;
|
||||||
var newTransform = CGAffineTransformIdentity;
|
var newTransform = CGAffineTransformIdentity;
|
||||||
|
|||||||
Reference in New Issue
Block a user