Author Topic: UIScrollView soft scroll in iPhone5  (Read 8075 times)

Cris_Chile

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
UIScrollView soft scroll in iPhone5
« on: June 30, 2014, 06:40:28 PM »
Hi all!

I have a question, because I see that the scroll movement (or the drag movement) in a scrollview in iPhone5 is not soft (in Editor the movement is better)...
I'm downloading textures from the web (using www.texture ) and assigning it to every UITexture of the scrollview elements.
(Im using the UIWrapContent for endless scrolling).
How can I do the performance better, to have a soft movement in the scrollview in iPhone5?

Thanks for any advice!

Best Regards,

Cris_Chile.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #1 on: June 30, 2014, 07:11:20 PM »
This depends largely on how much stuff you have in your panel and if you're doing stuff that causes rebuilding the panel's draw call like moving widgets around inside the panel.

Remember, that the Editor has your full computer to work with, which is far more powerful than just about any mobile.

There are different ways of optimizing the panels, but no real magic bullets.

*Don't animate things inside the panel
*make the panel cull while scrolling
*make sure you don't do unnecessary computations while scrolling.

This is all pretty basic stuff, that you in general should follow as good practices. If you want to get a little more advanced, you can do stuff like have your content be represented by containers instead of the "raw data", so you switch around N containers, even though you have M amounts of things in your dataset. N being the amount of containers needed on your screen at one time, and M being the full data set. Then you should be able to switch out the content of a given container with your data as you scroll. This is totally doable, but takes some work to get nice.

Cris_Chile

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #2 on: July 03, 2014, 11:22:58 AM »
Hi Nicki! Thanks for your advices, they are very usefull!  :D

In my app the elements of the scrollview don't move inside the scrollview, and I have activated the "Cull widgets while dragging them" option in the ScrollView. And I don't use any of the events (OnPress, OnDrag, ...) and I don't use the Update() methot neither. I have made a simple project, just with a scrollview, to fix this thing.
I just use the method "SetItemData (GameObject go, int wrapIndex, int realIndex)" to update the text info and the one image for every of the 4 containers in the Scrollview. I wanted to use the UIWrapContent instead of the UIGrid, because I have to load info from 100 elements (that's why I have to download every texture from the web, and then load it in one container that has to be shown in the ScrollView)..

I just noticed that on iPhone 5s (and in iPad), the movement of the scroll is not so soft (or continuous) like the iOS native scroll movement.

I have added a rigitbody to every container of the Scrollview, and I changed the vSync Option (I try with the 3 options available), and the Time in the Physics (between 0.0001 and 0.5), but I just can't see the same "soft" movement of the 4 containers in the ScrollView like the iOS native scroll option...

I will appreciate any other advice in the configuration of the scroll movement.

Thanks!!  ;D

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #3 on: July 03, 2014, 01:23:40 PM »
For movement once you've started dragging, there will always be a little bit of lag compared to native iOS, because of Unity having a little bit of overhead.

There's also a setting on UICamera which decides when it should count a touch as drag (Touch Drag) in the thresholds section. This can make it appear that there is lag when you first drag, as the touch drag is set quite high by default (40 px). Lowering this to 10px or less can make it feel much nicer.

Cris_Chile

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #4 on: July 03, 2014, 02:16:58 PM »
Thanks for this advice Nicki! I didn't know it!  ;D

In the "UI Root" -> "Camera" -> "UICamera" Component -> "Thresholds" section I tryed changing the "Touch Drag" from 40 px to 10 px, to 4 px, and to 1 px.
But I still see the movement not so "continuous"...
I wish you could see this. I have made a comparison between an iPhone 5s with the Unity simple project with NGUI scrollView and an iPad with the App Store scroll. I scroll both simultaneously, in this situation you can see clearly the effect that I'm talking about.

I have uploaded a video of this comparison in YouTube, and you can see the movement:

Link: https://www.youtube.com/watch?v=OURl3dQ9mLg

I hope there's another advice to do this scroll mak better..  :P

Thanks!!  ;D
« Last Edit: July 03, 2014, 02:23:20 PM by Cris_Chile »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #5 on: July 03, 2014, 03:15:02 PM »
Hmm, it seems to me that the iOS scroll is using some sort of smoothing on the input, which makes it start and stop smoother than the raw input would suggest - you'll notice that the content does not follow your finger 1-to-1, but instead catches up after a little bit.

You might be able to do something similar, but you have to eitehr make it custom in UICamera or add filtering to the scrollview's OnDrag input.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #6 on: July 04, 2014, 01:55:28 PM »
Yup, iOS scroll view drag input is definitely smoothed out on purpose. As Nicki pointed out it doesn't follow your finger right away, but rather seems to "spring" toward it.

Cris_Chile

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #7 on: July 07, 2014, 10:57:24 AM »
Thanks Nicki and ArenMook for your advices, I really appreciate them!  :D

Maybe my english is not good enough  :P ..
My probem is not in the translation movement itself (if it follows my finger right or not)..
My problem is in the visualization of the movement...
I see like the "refresh" of the frame is slower in the scroll of NGUI than in the scroll of iOS (it's like a "delay" in the movement)...
I attached an image of this problem, may be with this image it can be seen clearly... :D

I hope there's another advice to do this movement better..  :P

Thanks for any help! :D
« Last Edit: July 07, 2014, 05:17:31 PM by Cris_Chile »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #8 on: July 08, 2014, 08:46:13 AM »
That's not NGUI-related. Anything related to refresh rate in rendering isn't NGUI, it's Unity or the device itself. Did you change your target framerate to 60? It's going to be 30 by default.

Cris_Chile

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIScrollView soft scroll in iPhone5
« Reply #9 on: July 09, 2014, 12:52:33 PM »
Thanks ArenMook!!! :D

You were totally right!!!
Actually this wasn't a problem of NGUI, it was a problem of Unity...

As you suggested, I made some test with the Application.targetFrameRate variable.

Because there says that: "If vsync is set in quality setting, the target framerate is ignored, and the vblank interval is used instead", I tested turning on and off vSync and with: Application.targetFrameRate = 300, = 60, = 30,
and the best option that I saw was:

- Setting vSync to "Every vBlank" ( QualitySettings.vSyncCount = 1; )
- Changing the target framerate to 60

  1. void Start() {
  2.         Application.targetFrameRate = 60;
  3.     }

Thanks ArenMook, you rock!!!!!  :D :D :D