tencent cloud

Feedback

Device Orientation

Last updated: 2024-11-21 18:48:11

    stopDeviceMotionListening

    The method of utilizing this API is wx.stopDeviceMotionListening(Object object).
    Function Description: Cease monitoring alterations in device orientation.
    Parameters and Description: Object object.
    Attributes
    Types
    Default value
    Required
    Note
    success
    function
    -
    Not required
    Callback function for successful interface invocation
    fail
    function
    -
    Not required
    Callback function for unsuccessful interface invocation
    complete
    function
    -
    Not required
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    startDeviceMotionListening

    The method for utilizing this API is wx.startDeviceMotionListening(Object object)
    Function Description: Initiates monitoring of device orientation changes.
    Parameters and Description: Object object.
    Attributes
    Types
    Default value
    Required
    Note
    interval
    string
    normal
    Not required
    The execution frequency of the callback function monitoring device orientation changes, valid values are:
    game: Suitable for updating the callback frame rate of the game, approximately every 20ms.
    ui: Suitable for updating the callback frame rate of the UI, approximately every 60ms.
    normal: Regular callback frequency, approximately every 200ms.
    success
    function
    -
    Not required
    Callback function for successful interface invocation
    fail
    function
    -
    Not required
    Callback function for unsuccessful interface invocation
    complete
    function
    -
    Not required
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    onDeviceMotionChange

    The usage method for this API is wx.onDeviceMotionChange(function listener)
    Function Description: Monitors device orientation change events. The frequency depends on the interval parameter of wx.startDeviceMotionListening(). You can use wx.stopDeviceMotionListening() to stop monitoring.
    Parameters and Description: function listener, the monitoring function for device orientation change events.
    Attributes
    Types
    Note
    alpha
    number
    When the X/Y coordinates of the mobile device coincide with the X/Y coordinates of the Earth, the angle of rotation around the Z-axis is alpha, with a range of [0, 2*PI). Counterclockwise rotation is positive.
    beta
    number
    When the Y/Z coordinates of the mobile device coincide with the Y/Z coordinates of the Earth, the angle of rotation around the X-axis is beta, with a range of [-1*PI, PI). Rotation with the top facing the Earth's surface is positive. It may also be positive when facing the user.
    gamma
    number
    When the X/Z coordinates of the mobile device coincide with the X/Z coordinates of the Earth, the angle of rotation around the Y-axis is gamma, with a range of [-1*PI/2, PI/2). Rotation with the right side facing the Earth's surface is positive.

    offDeviceMotionChange

    The usage of this API is wx.offDeviceMotionChange(function listener).
    Function Description: Removes the monitoring function for device orientation change events.
    Parameters and Description: function listener, the monitoring function passed into onDeviceMotionChange. If this parameter is not provided, all monitoring functions will be removed.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onDeviceMotionChange(listener)
    wx.offDeviceMotionChange(listener) // The same function object as used during monitoring must be passed in.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support