Gesture recognizer for tap event at specific positions on the screen - objective-c

I am displaying hundreds of thumbnails in my view . I know default way to handle tap on thumbnail is using UICollectionView delegate method "didSelectItemAtIndexPath" but since its many thumbnails i wanted to look into adding gestures to the screen position so when i tap on a particular spot on the screen, it will handle the event accordingly for that particular thumbnail underneath. I would like to know if it is a good/possible approach?

It would be a hell of a lot easier to use a UICollectionView.
If you need a custom layout then you can subclass UICollectionViewLayout and get some really cool dynamic layouts.
You also get the added bonus of dequeued cells meaning that you get better memory management using it.

You may find UIGestureRecognizer useful. A good tutorial to get you started is here.

Related

iOS horizontal swipe room selection

I am making an iOS app for remote controlling the lights in my house. I have a list of groups of bulbs (rooms) that can be turned on and off. My problem is selecting a room, I want it to be like this:
You can either press the arrows left or right to switch the room, or you can put your finger, where it says Living Room and swipe left or right to switch it.
Can someone give me a pointer as how to implement a swipe feature like that? I know there are gesture recognizers. I never used them, but I guess they won't automatically make the text I want to swipe follow my finger.
I guess it would be possible to use the gesture recognizer and manually move the text to get the swipe "feeling". It just seems to me like there should be an easier solution.
I've done something similar several times, and the most elementary way to approach it is to override the touches... methods on NSResponder. This will tell you when a user's finger touches the component, when it moves, and when they let go. From that, it's pretty easy to adjust the position of your UIView, do some custom rendering, or whatever else you need.
Another, higher-level, approach is to use a UIScrollView and implement it's delegate methods. Inside the scroll view are three elements which completely fill the viewport: the one you can see, and those to the left and right. You watch the delegate events for the user adjusting the position of the viewport and as they expose an element to the left or right, you can snap the viewport into place when they let go. Then, you adjust the three inner views to show the appropriate new content and reset the viewport to expose the middle element (which would then be showing the appropriate content).
There are undoubtedly many other approaches, but I've used both of these with good effect.
I solved it in the end by using a pangesturerecgonizer attached to the label. It's pretty straight forward, I just didn't know pan is supposed to mean something like drag and drop, I thought pan would be something completely different.

How to draw in code an imageview

I have a problem. I want for each record in my core data database to draw an UIImage view on screen. But the problem is that I want to make a sort of grid. On the link below you see what I want to achieve.
picture
So my question is, how do I draw an image on screen in code. And place those images in a sort of a grid. using a collection view is no option, because the app should be running on all IOS devices.
While you could implement a custom UIView and implement the drawRect: method and draw UIImages there, I suggest just using multiple UIImageViews as subviews on your "main" view. Your view might be embedded in a UIScrollView, or you could use a UITableView with custom UITableViewCells. Whichever is easier is probably related to how you can interact with the view.
Building that one huge image view is something that I'd definitely try to avoid - it costs many many (probably unnecessary) memory, and it might be slow as well. Definitely not very flexible to handle, and a pain to update dynamically.
A quick cheat for something like this is to use a Table View and then in each cell to place another TableView but rotated at 90 degrees.
You can then use this second TableView to display the pictures etc...
This will give you a table that scrolls up and down and then each cell can scroll left to right.
I'd suggest subclassing UITableViewCell and setting it up as a UITableViewDelegate and UITableViewDatasource.
You will also have to remember to rotate the content of these "sub"tables by 90 degrees also so that they are the right way up.
This sounds like a lot of work but if you push the management of the sub Tables into the cells then it actually becomes quite easy.

PopOut a middle Image in a UIScrollView contain many images

I have problem in playing with the UIScrollView i am using a customImage Object class to display images on scroll view and event fire on each image i achived it all but i have to do a extra work on it as the giving image showing that the middle image is pop out and fire event for that popout image...
i am confuse in it can anyone tell me how to achive this ....
please told me some steps to start with it..
You should be implementing the UIScrollViewDelegate protocol in the controller which should be handling the UIScrollView.
In there you will get a plethora of delegate callbacks such as when the scrollView moves or is decelerating towards a complete stop etc.
"UIScrollViewDelegate iOS reference"
You can implement any of the methods to suit your exact needs and modify the image's properties. To find which image is in the middle you would be comparing the contentOffset property of the scroll view o image locations.

Replicating iOS 5 Stocks Widget

Anyone have any ideas on how I could go about replicating the scrolling stocks ticker in Notification Center on iOS 5?
What I'm thinking is using a UIScrollView, and use a UIView subclass for the items in the ticker. Would using an NSTimer be the best way to have it scroll automatically? How would I handle manual scrolling acceleration and deceleration like the Apple stocks widget does?
Also, how do I handle infinite scrolling?
Thanks for any suggestions.
Try AutoScrollLabel. It's a relatively old class, but the code design and animation behind it may be useful. If I understand correctly, it's a UIScrollView that holds two labels, each saying the same thing, resulting in "scrolling" as it animates between them. I'm sure you could take that concept and the drawRect: method in the code to create your own subclass of the UIScrollView and animate whatever content you want, complete with infinite scrolling. There may very well be an easier way, but I've used AutoScrollLabel in a few apps and it's easy to use and works without a problem. Let me know if you need more info/a usage example. Hope this helps!

programmatically implement UIScrollView in a UIAlertView

I would like to programmatically Add a UIScrollView in a UIAlertView.
I found a way to do that but I was not successful in adding text to this UIScrollView (using the same code as in here: https://www.youtube.com/watch?v=4SG0CAAl5u0).
is there an alternative to do that? the text I have is very long and I need people to be able to scroll but without being able to edit it.
I know that the Apple user interface guideline does not recommend long text in alerts (although detecting WiFi networks does that) but I have no choice but doing it
If you add a large text in UIAlertView it automatically becomes scrollable.
You don't have to do any thing to make it scrollable.
Here is a control on github that has a tabelView inside it. If you need to customize beyond what Inder suggests, you might want to look at the code and replace the tableView with a scrollView.
Also, there are other controls at cocoacontrols.com that might help you directly or give you some ideas.