adding images to UIScrollView - objective-c

There are 20 images.
When scrolling the UIScrollView, I want to add the image to UIScrollView (one by one). How to do this ?
Please help me to do this.

Apple have sample code that shows how to do this, called "photoscroller":
http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?code=y&source=x&bundleID=20645
This was part of a WWDC 2010 presentation, and the accompanying video is very good at explaining why things are done like they are:
http://insideapple.apple.com/redir/cbx-cgi.do?v=2&la=en&lc=&a=kGSol9sgPHP%2BtlWtLp%2BEP%2FnxnZarjWJglPBZRHd3oDbACudP51JNGS8KlsFgxZto9X%2BTsnqSbeUSWX0doe%2Fzv%2FN5XV55%2FomsyfRgFBysOnIVggO%2Fn2p%2BiweDK%2F%2FmsIXj

1°) You need to use the contentOffset property which will indicate you where on the scrollView you are (try to do some NSLog, you should understand ;-))
2°) Then combine this property with a delegate method of UIScrollViewDelegate to know when a scroll occurred.
3°) Third in the function you calculate the images needed to be printed (with the property in the first step).
And finally you add the images !

Related

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.

Is there a tutorial somewhere about designing a really large view and put it in scrollView using storyboard

The question may be similar with
Designing inside a scrollview in xcode 4.2 with storyboards
but none of the answer there makes sense at all.
Okay I created a new controller and I added a scrollView.
The very first thing I noticed is there is NOWHERE to specify the content size of the scrollView.
Not in attributes inspector, not in size inspector.
Then what?
I am expecting some larger than normal box where I can draw all the view I want to put in. There is no such thing either.
I am very frustated.
All the "tutorial" out there tell about how to fill scrollView using code.
Another thing I tried is to select controller go to size inspector and then choose FREEFORM.
Great. I still can't make that template big.
Should I do this in XIB instead? At least on that one I can have one huge UIView. Or what is the official way industry standard way of doing this? Is there a WWDC for this one?
Say I want to draw something like these:
I don't think you can get a tutorial on this as it is simply impossible in IB. As most people already commented out what you want to do here need to be done programmatically.
If you are using XIB you can set up all your content there. Under the size tab (in the inspector) you will need to change the height to fill all your content but you still need to set up your contentSize programmatically.
For storyboard I don't think it is possible to change the size of your scrollview in IB.

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!

NSTextField subclass for sliding text - Objective-C/Cocoa

I want to do what is described here. I know I am kinda repeating the question but that post does not have an answer. I have searched the net and didn't find anything I could understand either.
So, here is my problem: I want to create an NSTextField subclass that animates text (in the way described by the other post) when the text is too long to be completely displayed. I have absolutely no idea on how to do this, so some sample code would be nice for complicated answers. If it helps, I only want to use this to animate labels (text not selectable nor editable). Thanks.
It seems that this SO entry is close to what you need. It is not based on a NSTextField but on a NSView, but the result is what you are looking for and it should note be hard to modify.
Those links should show you the way :
Making uitextview scroll programmatically
Auto Scrolling UITextView Problem
They talk about iPhone classes, but I'm sure you will be able to adapt them for NSTextField.

Rotating MapView according to compass

I'm working on Map application that needs to work like original MapView on iOS.
I need to rotate mapview according to compass heading value. I tried MTLocation example also I also tried this answer But my results is not good.
Please see the screen shot.
When I rotate mapview according to heading value Map is rotating but as you can see on screen tiles is missing.
How can I solve this display problem ?
Regards
- Fatih
Hy,
I'm the author of MTLocation. Thanks for using it by the way!
For this to work you have to make sure, that your MKMapView is a subview of your ViewController's view (and not the view itself). Then you have to increase the frame of your mapView with a simple Pytaghoras - calculation: the width and height must be at least as big as the diagonal: sqrt(visibleWidth[320]^2 + visibleHeight[480-88]^2) = 506.
So that means
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(-100,-100,520,520)];
Hope that helped, please consider upvoting if it fixed your problem.
You can consider using a bigger frame for the MKMapView object. It should probably be a square with each side equal to the length of the device's diagonal. The problem with this approach is that there are regions of this object that the user won't see but we process information like views for annotations related to that region anyway. Other properties like visibleMapRect would be least helpful.
Another alternative would be to be zoom in by scaling the MKMapView object on rotation. But this might make the map blurry (untested). You could zoom out on the region displayed in the map but it could lead to frequent refreshes. You can look at a middle ground where you don't zoom out until the map is rotated over a certain angle. You can also look at using two views where one of the views is off screen and updated so that it can replace the view after a certain amount of rotation so that it feels seamless.
I am working towards making my own maps application in iPhone. I want my maps to rotate as the user turns. I tried setUserTrackingMode available in iOS 5, but due to some reason it doesn't work. So I decided to take help of MTLocation framework here.
Till now I have done the following.
created a new project and copied all .m and .h files in that.
Import MapKit.h and MTLocation.h.
In Viewcontroller.h, defined property for mapView (should I define a property for locateMeItem).
In ViewDidLoad, paste the code given at the end of the page here.
I get a few errors:
Can't see the locateMe button when created programatically.
Undefined property headingEnabled.
myCustomSelector has no effect.
self.toolbar- toolbar is not a instance of ViewController.
I have tried a code at gist[dot]github[dot]com/1373050 too, but I get similar errors.
Can anybody explain a detailed procedure of this.