Replicating iOS 5 Stocks Widget - objective-c

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!

Related

How can I fix the flicker occurring when selecting an NSCollectionViewItem?

I've got an NSCollectionView which houses three columns of NSCollectionViewItems. In each of the NSCollectionViewItem prototype views, I have a single NSImageView. As far as I'm aware, this is a fairly standard setup. I think the problem stems from my use of a popover to present the collection view, but I'm honestly not sure. Basically, the problem I'm having is that when I click on one of the aforementioned NSCollectionViewItems to mark it as "selected," every once in awhile it flickers/flashes. It's not a total deal-breaker, but it's annoying enough to make me post this question.
Coming from the HTML/CSS/JS game, I started to think of all the ways I would prevent the flicker when building stuff with web technologies. My first thought was to make certain parts of the NSCollectionView (and subviews) layer-backed. I figured that by doing the drawing via layers or just setting the collection view to be layer-backed period, it would render better, kind of like GPU-enhanced animations in CSS (e.g. no sub-pixel antialiasing, enables z-depth, etc.).
So, I subclassed NSCollectionView and added a [self setWantsLayer:YES] in the
-(id)initWithCoder:aDecoder method. I was right! It removed the flickering altogether. Also, the scrolling became much smoother. However, in the process of making the flicker go away, everything else started messing up. The popover would take about 10s to load (vs. ~500ms originally), items would do weird overlapping things, etc.
My question to you all is this: what should I do? If anyone could help a brother out, I'd really appreciate it.

Gesture recognizer for tap event at specific positions on the screen

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.

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.

how to make a UIScrollView track something?

i want my app to be able to track a person when he moves 2 dimensionally upwards. I already have a vertical scroll view, and it works, but when i press a button i want it to track a little stick figure as he walks vertically, how can i control this? i thought of setting the scrollview.contentoffset to a certain position, but it just changes it one time when i want it to change it fluidly. i suppose i could make a timer that updates the contentOffSet every like .001 seconds or something, but i thought there maybe a better way.
Also, while i was searching the UIScrollView's methods, one of them was an isTracking method, which is a boolean, and I'm assuming it returns yes if the scrollview is tracking something, so given that i assume there is a feature in scrollview so that you can track things. Also, if to track things you have to use some other framework thing that would be helpful to know too
THANKYOU FOR ANY HELP!
The property tracking tells if the scroll view is currently tracking the user's movement. So that definitely won't help you out. (See David H's post for a better explanation for what the property indicates.)
However, you could use setContentOffset:animated: and set animated to YES. That results in a smooth transition to the new content offset.
Instead of calculating a reasonable content offset you might find it easier to specify an area that contains the stick figure. If so use scrollRectToVisible:animated:. Obviously animated should be set to YES.
1) don't use contentOffset = x;, use "- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated". Experiment how often you need to send this message, but I'm guessing you can do it no more than 10 times a second and get nice results.
2) isTracking means the user has their finger on the scrollView but has not started dragging it. By testing "isTracking" and "isDragging" you can determine if the user is fiddling with your scrollView or not.

Lazy-loading Custom UIScrollView with dynamic grid size?

So I wrote a custom subclass of UIScrollView that basically displays rectangles in a 2-column grid, but while the width of each is fixed to half the width of the iPhone/iPad screen, the height varies, depending on the dimensions of the picture within it. All's well and good now, but I can imagine that after adding lots of these subviews to my UIScrollView subclass, things are going to lag. So I'm trying to implement lazy loading analogous to UITableView's dequeueing reusable cell method.
I've looked at a handful of other questions on SO, but they all involve paging based on full-screen photos, including Apple's WWDDC PhotoScroller example.
Anyone have any insight? Thanks.
You basically want to keep track of the views that are scrolled off screen and reuse them.
You might want to check out ATArrayView. It implements a recycling mechanism like what the UITableView has except with a UIScrollView with an arbitrary number of rows and columns?
I've used it as the basis for my own image scrolling code and is pretty good. It's delegate methods follow the spirit of UITableView data source and delegate protocols.
Good luck
Tim