Author Topic: Swipe in window  (Read 2136 times)

xbelt

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 9
    • View Profile
Swipe in window
« on: March 24, 2014, 05:45:46 AM »
Hello,

I am fairly a beginner with NGUI but currently stuck on a problem.
I want to be able to perform a swipe gesture from the left border of the screen and with that swipe gesture show (animated) a new window where certain settings are stored.
What is the best way of implementing this?
I thought about a scrollView where a part is hidden outside the screen and is just swiped in, but I need the shown window to snatch itself at the screen borders.

As an example watch the reddit app. When you chose a ctegory you can always swipe the category view back in.

I apologize if this question has been asked before, but I did not find anything on my reserach.
Kind regards

Lukas

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Swipe in window
« Reply #1 on: March 24, 2014, 05:22:42 PM »
To have a window be always on the edge of the screen, anchor it (check documentation for UIRect).

Swipe gesture can either be detected using a dedicated tool for that such as Finger Gestures, or by adding some code using NGUI's existing events.

First you will want to set the UICamera.genericEventHandler to your game object that will hold your gesture detection script. This script will receive a copy of all the events.

Then you will need to create this script. Inside, add the OnPress function.

OnPress(true) set some internal variable to 'true' indicating that you've started your drag event (assuming the drag started where you need it to start). Record the touch location if you need it (UICamera.currentTouch.pos). Inside OnPress(false) check the distance between the saved location and the current touch position (UICamera.currentTouch.totalDelta). If the distance was far enough and happened quickly enough, slide in your window by activating a tween.

If you want it to be gradual like the dock menus on iOS/Android, then you will also need to add appropriate logic to OnDrag.

xbelt

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 1
  • Posts: 9
    • View Profile
Re: Swipe in window
« Reply #2 on: March 25, 2014, 03:52:22 AM »
Thank you for your great answer. I will try to implement it in this way.