Graphic scrolling in iPhone SDK - iphone

I have a graphic that is 3 times the width of an iphone landscape view.
I am trying to auto scroll it so that it appears that it is moving sideways, without using the touchscreen scrolling method.
My aim is to maybe have a button you can press and it moves it left or right across the screen like an animation.
I can deal with everything else but am having trouble finding a solution.
Any example code would be appreciated or even any info on whether it is possible or not.
Thanks. Dave

You can wrap a UIView in an animation block. The animation sweeps the origin value in its frame property from one point to another, over a set period of time.

Related

Continuously scrolling UI Unity

So I am working working on something in unity (2d game). I have a list of button (UI) on my scene and I want to implement a scrolling mechanism. What is the best way to go about it? Currently , I can scroll through horizontally because I have added a "scroll rect" to the the canvas holding the buttons as I start the game. However when I try to scroll back (horizontally, it goes beyond the Buttons. Is there a way to make the scrolling continuous such that as I scroll, from the first UI element when I get to the last one and I keep scrolling, it continues with the first element. or what should I do. please let me Know If i should clarify.
In the Scroll rect you can set the movement type. I don't think the kind of "infinite scroll" you are asking for is available.
For your case, I think that the Use Elastic or Clamped mode to force the content to remain within the bounds of the Scroll Rect should do the work.
In the case of the infinite scroll specifically needed, you would need to ask for that explicitely and show your attempt for more specific help.

endless vertical scrolling background

I want to make an endless vertical scrolling layer that gives the impression that the main character is moving upwards. I have been brainstorming on how to achieve this.
My issue is that I want objects to appear as if they are coming from above and below the screen at the same time. Secondly, I want to be able to move the main character to create and destroy box2d joints between it and some of the objects appearing on the screen. What is the best way to achieve this with consuming too much memory? I would appreciate any help on this.
Apple did a wonderful tutorial of this in a WWDC 2011 video session. It was "UITableView Changes, Tips & Tricks" and it's about 35m40sec into the video.
Since the use of the UITableView is really just a UIScrollView for the purposes of the background, you could just use a UIScrollView and you can either have it move on timer or events as needed.
Think of your player as moving within a stationary bounding box. The background can scroll using the aforementioned pooling method (as the background tile scrolls off the screen it is placed into a pool, and before a new tile is instantiated the pool is checked for available reusable tiles). Thirdly, your enemy objects will simply approach from either the bottom of the screen or the top.
Imagine your idea without the scrolling background (flying effect) and you should find that the problem is relatively straightforward.
I also needed and endless scrolling background layer. This can do exactly that, and it is super simple to set up and use. Just copy the four files in to the cocos2d folder in your project, then follow the quick tutorial seen on the github. Make sure the image you use is seamless (when you line them up vertically you can't tell where one ends.

Really, really big UIScrollViews

I'm trying to make a level-of-detail line chart, where the user can zoom in/out horizontally by using two fingers, and grow the contentSize attribute of the the UIScrollView field. They can also scroll horizontally to shift left or right and see more of the chart (check any stock on Google Finance charts to get an idea of what I'm talking about). Potentially, the scroll view could grow to up to 100x its original size, as the user is zooming in.
My questions are:
- Has anyone had any experience with UIScrollViews that have such large contentSize restrictions? Will it work?
- The view for the scroll view could potentially be really huge, since the user is zooming in. How is this handled in memory?
- Just a thought, but would it be possible to use UITableViewCells, oriented to scroll horizontally, to page in/out the data?
This is kind of an open ended question right now - I'm still brainstorming myself. If anyone has any ideas or has implemented such a thing before, please respond with your experience. Thanks!
This is quite an old topic, but still I want to share some my experiences.
Using such a large UIView (100x than its origin size) in UIScrollView could cause Memory Warning. You should avoid render the entire UIView at once.
A better way to implement this is to render the only area which you can see and the area just around it. So, UIViewScroll can scroll within this area smoothly. But what if user scrolled out of the area that has been rendered? Use delegate to get notified when user scroll out of the pre-rendered area and try to render the new area which is going to be showed.
The basic idea under this implementation is to use 9 UIViews (or more) to tile a bigger area, when user scrolled (or moved) from old position to new position. Just move some UIViews to new place to make sure that one of UIView is the main view which you can see mostly, and other 8 UIViews are just around it.
Hope it is useful.
I have something similar, although probably not to the size your talking about. The UIScrollView isn't a problem. The problem is that if you're drawing UIViews on it (rather than drawing lines yourself) UIViews that are well, well off the screen continue to exist in memory. If you're actually drawing the lines by creating your own UIView and responding to drawRect, it's fine.
Assuming that you're a reasonably experienced programmer, getting a big scroll view working that draws pars of the chart is only a days work, so my recommendation would be to create a prototype for it, and run the prototype under the object allocations tool and see if that indicates any problems.
Sorry for the vagueness of my answer; it's a brainstorming question
But still, this approach (in the example above) is not good enough in some cases. Cause we only rendered a limited area in the UIScrollView.
User can use different gestures in UIScrollView: drag or fling. With drag, the pre-rendered 8 small UIViews is enough for covering the scrolling area in most of the case. But with flinging, UIScrollView could scroll over a very large area when user made a quick movement, and this area is totally blank (cause we didn't render it) while scrolling. Even we can display the right content after the UIScrollView stops scrolling, the blank during scrolling isn't very UI friendly to user.
For some apps, this is Ok, for example Google map. Since the data couldn't be downloaded immediately. Waiting before downloading is reasonable.
But if the data is local, we should eliminate this blank area as possible as we can. So, pre-render the area that is going to be scrolled is crucial. Unlike UITableView, UIScrollView doesn't have the ability to tell us which cell is going to be displayed and which cell is going to be recycled. So, we have to do it ourselves. Method [UIScrollViewDelegate scrollViewWillEndDragging:withVelocity:targetContentOffset:] will be called when UIScrollView starts to decelerating (actually, scrollViewWillBeginDecelerating is the method been called before decelerating, but in this method we don't know the information about what content will be displayed or scrolled). So based on the UIScrollView.contentOffset.x and parameter targetContentOffset, we can know exactly where the UIScrollView starts and where the UIScrollView will stop, then pre-render this area to makes the scrolling more smoothly.

iPhone Slider Sensitivity

I have custom slider that I use the following touch event to respond to:
[bSlider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
I find it very difficult to use, it does not respond to touches about 50% of the time. Compared to the volume slider with the music player that works great every time you touch it. Are there any secrets to creating a slider in code that will make it more responsive?
I had the same problem with my custom UISlider and solved it by using a larger "thumb" image with transparency around the outside.
I also had problems with my callback function running slowly and causing the slider to be very laggy and clumsy to use, which I fixed by adding a simple check at the top of the function:
int val = ceil(sliderView.value);
if (val == _lastSliderVal) return;
_lastSliderVal = val;
// .. code to update various display elements based on slider value
After changing both of these, the slider works beautifully.
The problem is the event you are tracking. UIControlEventTouchUpInside means that your -start method will only get called if you lift your finger up while it is still in the bounds of the control, something that's not easy to do on a slider.
What you probably want is UIControlEventTouchUpOutside and/or UIControlEventTouchDragExit, which will call -start either when you lift your finger outside of the control's bounds, or when your finger is dragged from within a control to outside its bounds, respectively.
See the UIControl reference for more info.
Well I tried several things including the suggestions above but never got my slider to work as well as the iPhone volume slider in the music app. The only thing that helped was to add a clear background around the button image to make the touch space larger. That created problems getting the button to slide all the way to the bottom and top of slider that I never completely resolved. Now with OS 3.0 is seems to be working much better.

Iphone Scrollview Question

i am quit new at iphone development and trying to make a photo collage software while learning it. Right now i have a lil problem and hope you can help me out.
I have an UiviewController with a view in it, in this view i have 7 scrollviews with uiimagevies in them for zooming and scollign images within these scrollviews.
All that works well but now i want to make these 7 scrollviews dragable and maybe if possible zoomable (so that the image within the given scroolview zoom together with the scrollview).
It should be possible to drag them all around the screen and if possible even overlap them
and by the way rotating would be great ;-) hope that is not to much asked for.
Would be great if someone can help me out with this..
Well you've got to decide on some other choice here because the functionality you are asking for overlaps, and you can't ask the app to magically know which the user wants to do. What I mean by this is that when you touch and drag within a scroll view, it's going to try to scroll itself, rather than drag the entire scroll view around.
As for rotation and zooming - that gets more complicated, because you start dealing with vector math and the like. You can check out my question on rotation here. The link I gave you has the code to get both rotation and zooming to work.