I'm looking for a MKMapView which can be scrolled continuously in any direction and repeats itself. It has to be a MKMapView/subclass and not a custom Map-Framework like route-me.
How to implement that on top of a MKMapview?
I do not know if there's framework already for this, but here's an idea.
Use infinite scroll view sample from wwdc idea and apply it to mapview. So for example, use two mapviews side by side (for infinite scroll along X axis)
Usually one mapview will be shown, but when the dragging goes past the edges of the left/right, then you could slide one mapview out and slide in another mapview.
Your viewcontroller will need to add annotations to both mapviews of course, and if you want to support any direction, that can possibly mean you need 4 map views to cover corner case.
You can probably treat mapview as scrollview when doing this infinite scroll trick, as described in wwdc 2011 scrollview session.
To keep both mapviews in sync, you will need to pass messages between two, for example zoom level. Not sure if mapview has all things you need to observe these things, but do take a look. You could possibly use KVO to observe the internal variable without violating Apple private API check.
Good luck and let me know how it goes.
Related
I am working on an iPhone app and I was hoping someone could share their knowledge on which view controller would be best for functionality I would like to achieve.
I have two parameters x and y and I fetch text data from a web-service based on these two parameters. When a user performs a horizontal or a vertical swipe, I update x and y and fetch new data. This operation can be performed a very large number (thousands) of times in theory.
There are two things I am worried about here:
Performance. Since we can have a large number of swiping operations performed, there should be a method for deallocating data when not needed.
Smooth transition. I would like both the horizontal and vertical transition to be smooth, with the possibility to stop midway, as if transitioning between pages in a UIPageViewController.
I have done research on this and I have found these options so far:
UIViewController with gesture recognizers. This is what I have currently coded. I am using gesture recognizers to update data. For transitions I am using a method with CATransition. The problem with this method is that the transitions are not smooth and cannot be stopped midway. I guess I could spend more time on the transition method and make it work nicely, but that seems like a solution which is not elegant and horrible for maintenance, as Swift provides us with other view controllers which have this implemented. I am also not sure how the app would perform in this situation after hundreds of swipes.
UIPageViewController. I read that it is possible to do a vertical UIPageViewController inside a horizontal UIPageViewController, so that I could swipe in either direction to a new page. However, I am not sure if this is the right solution with dynamic content of possibly thousands of pages.
UICollectionViewController. As far as I understand, I could probably use UICollectionViewController for this as well.
Which view controller would have most suitable methods for this? I would like the solution to be elegant and easy to maintain further on. I don’t mind doing more research and figuring out how to do the coding, as long as I know which is the direction I should move in :)
Thank you!
I have five UIButtons in my application.All these UIButtons are stored in Array.As my Code Show below
NSMutableArray *Buttons = [NSMutableArray arrayWithObjects:btn1, btn2, btn3,btn4,btn5, nil];
Now i Want to move all these UIButtons in Specific Direction Continiously.As my image show below
I Already did some animation in CAkeyframeAnimation,but As a iOS beginer its difficult for me to perform these type of Continious Animation on multiple UIButtons using CAKeyframeAnimation.Can some one help me about this.Any help will be appriated.
I don't know what you've done already, but you could use UIView Animations and then make sure you enable set the UIViewAnimationOptionAllowUserInteraction option.
You can then put a gesture recognizer on the buttons.
To get it to animate, just use UIView's block based animations, there are only 4 that need to be done, and have them repeat. It's fiddly, but it's a quick and dirty solution.
If you are trying to move these buttons around in a way that keeps them reactive to user touches, using Core Animation directly is probably not your best bet. My answer below is based on this assumption.
When a Core Animation-based animation is running, the layer you see moving on screen (the "presentation layer" — see here for more info about this) does not register touches at its current position, but only at the final position of the animation, which is invisible for the user. Thus the moving bouton will behave most of the time as if it is disabled. Though it is possible to hack around this, it is not very convenient and not meant to be used that way.
Another drawback is that CAAnimation is not very flexible once created, for example it would be tedious to stop the movement of the buttons at their current position if you ever needed to.
Instead, you should compute and move your UIButtons frames manually. To synchronize the movement with the display refresh rate and have a smooth animation, use CADisplayLink, which is a very easy to use class that you can use to register a method that will be called back each time the display is being refreshed. In this method you should update your views frames based on the desired behavior of your views.
How can one enable horizontal and vertical scrolling at same time in a grid view?
If I have a 4x4 grid of thumbnail images, I want to implement swiping in both directions, left/right and top/bottom. Currently I am done with left and right swipe, but if I select the second cell and swipe towards the top, the 2nd row should be scrolled like a Rubik's cube.
Please share if any one have any idea.
It's been quite a while since your question but as I've been struggling with the same thing I'm gonna answer it for future reference...
Sadly I could not find a good solution anywhere so after a lot of hours of experimenting I came up with this: https://github.com/AlvinNutbeij/DWGridController
It's still a work in progress but very usable for your purpose I'd say!
How have you currently implemented what you have? Your mention of 'cell' makes it sound like you are using a UITableView. You won't manage to make one of those scroll in both directions, you'll need to work with a UIScrollView.
I suggest you watch "Designing apps with Scroll Views" from WWDC 2010, then "Advanced Scrollview Techniques" from WWDC 2011. That'll teach you about how you implement tiling and infinite scrolling.
Essentially what you want to do is implement some kind of view recycling yourself, that works like the way UITableView recycles its cells. When things are scrolled off one side of the scroll view, you remove the views for the things that just scrolled off screen and put them in a queue. When things scroll onto the screen, you pull views out of the queue (or create new ones if the queue is empty) and lay those views out in the correct place.
To do the infinite scrolling, you fake it: when your scroll view gets near its edge, you reposition everything inside it, you move the scroll view's content offset to where you've repositioned the views, and then you continue from there: it's all done at once so the user never notices.
The videos will explain these techniques better than I can sum up here: watch those as your first point of call.
When you're working with an atypical nested UITableViews setup - where you have an outer vertical UITableView that hosts 90° rotated UITableViews (see: Looking for a UI library to present Data horizontaly in iOS ):
is there a way to make iOS process vertical and horizontal touches at the same time?
I found that iOS is very clever in processing touches:
horizontal touches make the relevant horizontal UITableView scroll, while a vertical swipe makes the outer UITableView scroll. Perfect.
Only, I'd love to be able to move my finger diagonally and see the outer UITableView and the inner UITableView scroll at the same time.
I tried a few approaches (playing with canCancelContentTouches, delaysContentTouches, and touch messages) but I haven't found a way to make this happen.
EDIT:
Here's a XCode4 project that shows this behavior: http://marcanton.io/other/stackoverflow/nestedtableviews.zip
EDIT:
I submitted this issue to Apple Developer Technical Support, here's their reply:
Thank you for writing to Apple
Worldwide Developer Technical Support.
I am responding to your inquiry
concerning touch events in embedded
UITableViews.
Typically this is an approach that is
not recommended. The issue is that
UITableView inherits from UIScrollView
and as stated in the documentation for
UIScrollView:
"Important: You should not embed
UIWebView or UITableView objects in
UIScrollView objects. If you do so,
unexpected behavior can result because
touch events for the two objects can
be mixed up and wrongly handled."
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html%23//apple_ref/occ/cl/UIScrollView
So that this time, there is not a
workaround for getting both to scroll
at the same time.
I recommend that you file an
enhancement request at
http://developer.apple.com/bugreporter/
detailing what you would like to see
us add in a future release.
Still, I think that there has to be a way to enable this functionality, although I understand that this is not recommended. In fact, Apple does not even recommend hosting UITableViews inside another UITableView, but with the exception made above, it works quite beautifully.
I'll keep this question updated with our collective findings.
EDIT: There actually is a way, detailed here: http://marcanton.io/blog/nested-orthogonal-tableviews/
This would have to be a custom mirroring of intercepted touch events. Touch events follow the responder chain model, which means that if an object in the responder chain (the top most (outermost) view) cannot handle the event or action, it resends the message to the next responder (in this case the background UITableView in the chain). This is why you are seeing the horizontal events go to the horizontal UITableView and the vertical events going to the vertical UITableView. A diagonal touch event has applicable horizontal and vertical events, so the top-most view (the outer vertical UITableView) can respond to the vertical touches and swallows the event.
If you think about it, all vertical touches likely have a little bit of horizontal events (think about when you flick your finger), so there is likely some work done in the background to determine how to interpret the touch event (either as a vertical or horizontal).
I found this tread on passing events down to the next object in the responder chain. You might want to give this a try as a partial solution to your puzzle. The rest is to figure out how to capture the horizontal touch events and pass them along to the next responder.
Interesting, I haven't played around with this kind of setup yet, but I would try to intercept touch events on the nested UITableViews and delegate any vertical movement to the outer UITableView - and vice-versa.
I'm trying to figure out if I can get what I want out of UIScrollView through some trickery or whether I need to roll my own scroll view:
I have a series of items in row that I want to scroll through. One item should always be centered in the view, but other items should be visible to either side. In other words, I want normal scrolling and edge bouncing, but I want the deceleration when the user ends a touch to naturally settle at some specified stop point. (Actually now that I think of it, this behavior is similar to coverflow in this respect.)
I know UIScrollView doesn't do this out of the box, but does anyone have suggestions for how it might be made to do this, or if anyone's spotted any code that accomplishes something similar (I'm loathe to reimplement all the math for deceleration and edge bounce)
Thanks!
There is not a whole lot of trickery to this. Just use an UIScrollView with paging enabled. Make it the size of one of your items, and locate it where you want that item to appear. Next, disable the "Clip Subviews" option on the scroll view (either in IB, or programmatically), and you are all set.