Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UIScrollView Tutorial

myersn024myersn024 Posts: 315Tutorial Authors
edited December 2011 in iPhone SDK Tutorials
This is a simple tutorial on how to add a UIScrollView to your project.

Unfortunately, the embedded versions of these videos from vimeo.com aren't in HiDef. To see them in HiDef, you'll either have to view them at vimeo.com or you can download a HiDef version to your computer with the link below (about a 40 meg download). It probably bears stating that I am in no way affiliated with vimeo.com. One of the forum members here suggested them for video hosting, and I've been pleased with their service thus far. If anyone has a better suggestion, I'm all ears.

<object width="800" height="490"> <param name="allowfullscreen" value="true" /> <param name="allowscriptaccess" value="always" /> <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1642150&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" /> <embed src="http://vimeo.com/moogaloop.swf?clip_id=1642150&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="800" height="490"></embed></object><br /><a href=" ">iPhone Tutorial - UIScrollViews with pinch/zooming</a> from <a href="http://vimeo.com/user647705?pg=embed&sec=1642150">Nick Myers</a> on <a href="http://vimeo.com?pg=embed&sec=1642150">Vimeo</a>.
<a href=http://www.vimeo.com/download/video:85049636?e=1220544094&h=dc12c612c984ee803535865c1dcd3675>Download the HiDef version to your computer</a>
Post edited by myersn024 on
· ·

Replies

  • ChriBChriB Posts: 154Registered Users
    edited September 2008
    Thank you, great work! :)
    · ·
  • PiruzPiruz Posts: 49Registered Users
    edited September 2008
    Thanks you for this tutorial :D

    But I have a request : anyone could help me to have the scrollview centered on the screen when I zoom out ? I tried all the day, but I think I'm not enough used to this langage to find a solution :(
    Thanks by advance :o
    · ·
  • EricCartmanEricCartman Posts: 23Registered Users
    edited September 2008
    Hi, very nice tutorial. However, when I build and install this application onto the iphone. The pinching and zooming events are not always registered. The pinching gesture are sometimes registered as just tabs, any idea why?

    Thanks
    · ·
  • myersn024myersn024 Posts: 315Tutorial Authors
    edited September 2008
    I haven't installed this app to my phone to try it out. I'll do that a little later and see if I have the same problems.
    · ·
  • EricCartmanEricCartman Posts: 23Registered Users
    edited September 2008
    myersn024 wrote: »
    I haven't installed this app to my phone to try it out. I'll do that a little later and see if I have the same problems.

    Thanks for the reply. I have another question.

    I have been trying to add the scroll view to a view controller class. I added the UIScrollViewDelegate to the definition of the view controller class, and assigned the scrollView's delegate to self (the view controller), and finally added
    -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return myImage;
    }
    in the view controller implementation.

    Everything compiles fine. However, when I run it, the image is loaded into the scrollview, but it does not respond to any touch events (no panning, pinching etc..) Any suggestions?

    Thanks
    · ·
  • myersn024myersn024 Posts: 315Tutorial Authors
    edited September 2008
    I don't have a clue about the second problem you're having. My advice is to make sure that you have everything set up properly. I've compiled and ran the sample code that I provided with the tutorial, and I'm having the same problem that you are with the multi-touch zooming not always registering properly. I'm going to have to play around with it some more to figure out what's wrong there. Unfortunately, I didn't test the code on my testing device before posting the tutorial.....however, I'm sure that the fix is rather simple. If anyone out there can shed some light on this, I'd really appreciate it.
    · ·
  • EricCartmanEricCartman Posts: 23Registered Users
    edited September 2008
    myersn024 wrote: »
    I've compiled and ran the sample code that I provided with the tutorial, and I'm having the same problem that you are with the multi-touch zooming not always registering properly. I'm going to have to play around with it some more to figure out what's wrong there. Unfortunately, I didn't test the code on my testing device before posting the tutorial.....however, I'm sure that the fix is rather simple. If anyone out there can shed some light on this, I'd really appreciate it.

    Does any one have any insight on this issue?

    Thanks
    · ·
  • MaCeXpErToMaCeXpErTo Posts: 149Registered Users
    edited September 2008
    Is there anyway to make this scroll just vertically and not horizontally?
    "I love this place"
    · ·
  • myersn024myersn024 Posts: 315Tutorial Authors
    edited September 2008
    I'm pretty sure that you can lock the horizontal direction, but I haven't implemented it. Eventually, once I get caught up with school and work, I'll get back to this tutorial and answer some of the questions that people are asking........it's amazing how life gets in the way sometimes!
    · ·
  • MaCeXpErToMaCeXpErTo Posts: 149Registered Users
    edited September 2008
    myersn024 wrote: »
    I'm pretty sure that you can lock the horizontal direction, but I haven't implemented it. Eventually, once I get caught up with school and work, I'll get back to this tutorial and answer some of the questions that people are asking........it's amazing how life gets in the way sometimes!

    Oh, I hear ya man... I been having no time lately... So much college work:p
    "I love this place"
    · ·
  • myersn024myersn024 Posts: 315Tutorial Authors
    edited September 2008
    MaCeXpErTo wrote: »
    Oh, I hear ya man... I been having no time lately... So much college work:p

    Tell me about it. I've got a full-blown project for an object-oriented programming class that I haven't even started and I've been promising that an update to To Do's will be out the first week of October. WHAT WAS I THINKING???!!!!

    I'll be lucky to get anything finished in the next two or three weeks.....way too much going on and not enough time in the day! Oh well :)
    · ·
  • hemalimojidrahemalimojidra Posts: 12Registered Users
    edited November 2008
    Thnk you...It work..
    You can also take idea from....
    iPhone Dev Center
    · ·
  • elpuercoelpuerco Posts: 136Tutorial Authors
    edited December 2008
    I understand the tutorial and can replicate it with ease, but I cannot figure out how to have the code work so it is not all in the app delegate code?

    For example I want to have this code work in another view?

    Create a new project called test and you get the app delegate .h and .m files as well as the testviewcontroller .h and .m files.

    I am trying to get the scrollview to appear in the testviewcontroller files xib etc

    but all the referencing in the tut is in the delegates code?

    Any pointers?

    Thanks
    · ·
  • jbullfrogjbullfrog Posts: 141Registered Users
    edited June 2009
    Hello, im new to the forum and have a question about your scrollview tut. Can I just add a view to the scrollview, and have that view contain UIImages, and UIButtons? I think the answer is yes, but im having trouble getting things to work.

    Can I place the scrollview in my xib and the view and its contents into the scrollview in that same xib?

    Thanks
    · ·
  • Iphone14Iphone14 Posts: 25Banned Members
    edited September 2009
    Hey Guys,

    I'm having the same problem as elpuerco!

    Any help would be greatly appreciated!

    Thanks
    · ·
  • bobcubsfanbobcubsfan Posts: 3New Users
    edited October 2009
    Great tutorial. Thanks.

    In using the scrollview and getting different images, the images are "building up" so the scrollview is showing multiple images when the top image is pinched, zoomed and moved around.

    How can I clean it out so there is only one image in the view?
    · ·
  • bobcubsfanbobcubsfan Posts: 3New Users
    edited October 2009
    elpuerco wrote: »
    I understand the tutorial and can replicate it with ease, but I cannot figure out how to have the code work so it is not all in the app delegate code?

    For example I want to have this code work in another view?

    Create a new project called test and you get the app delegate .h and .m files as well as the testviewcontroller .h and .m files.

    I am trying to get the scrollview to appear in the testviewcontroller files xib etc

    but all the referencing in the tut is in the delegates code?

    Any pointers?

    Thanks

    -(void)scroller
    {
    //this gets an image from an SQLITE db

    [self getBillPic];

    initWithImage:billImage];
    self.myImage = [[UIImageView alloc] initWithImage:billImage];



    myScrollView.contentSize = CGSizeMake(myImage.frame.size.width, myImage.frame.size.height);
    myScrollView.maximumZoomScale = 4.0;
    myScrollView.minimumZoomScale = 0.75;
    myScrollView.clipsToBounds = YES;
    myScrollView.delegate = self;
    [myScrollView addSubview:myImage];
    }
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return myImage;
    }

    I placed this code in a ViewController. The UIScrollView in a XIB file
    · ·
  • mywa11mywa11 Posts: 6New Users
    edited November 2010
    it is interesting, but i have a question
    how can i dynamic cahnge image?
    for example i have a chess board, and user can add figures to the board
    how to make such application in this case? i can not just have an image of board, i have to change it every turn
    · ·
  • communati0ncommunati0n Posts: 6New Users
    edited February 2011
    wow thx cleared up a lot of issues
    EDIT: one issue tho, how do i put a scrollview into a viewcontroller?
    · ·
  • Helena158Helena158 Posts: 3New Users
    edited February 2011
    Great tutorial, thanks for your work ;)
    · ·
  • kshitijakshitija Posts: 3New Users
    edited April 2011
    Hi

    I am developing an application which has buttons to navigate through the various views. My 1st view is a Registration page which has a ScrollView. On clicking the next button on this page, the next view is displayed. On clicking the Back button in this page the previous view is displayed but you can no longer Scroll as earlier.

    Could anyone tell me why is it so?
    · ·
  • greatman1612greatman1612 Posts: 1New Users
    edited October 2011
    Anyone help me reason my applications don't debug. Download Code

    Thanks a lot!
    · ·
  • HighExistanceHighExistance Posts: 1New Users
    edited December 2011
    This doesn't help me.. I'm still having issues. Can someone please post a video or instructions on how id do this in Xcode 4.2 and with adding a picture under resources not the way its done here. Ive been trying the last 3 days to get a pinch zoom working for a photo.. :(
    Thanks!!
    · ·
  • sevenstarssevenstars Posts: 1New Users
    edited December 2011
    How to play pdf on website with Ipad?
    myersn024 wrote: »
    This is a simple tutorial on how to add a UIScrollView to your project.

    Unfortunately, the embedded versions of these videos from vimeo.com aren't in HiDef. To see them in HiDef, you'll either have to view them at vimeo.com or you can download a HiDef version to your computer with the link below (about a 40 meg download). It probably bears stating that I am in no way affiliated with vimeo.com. One of the forum members here suggested them for video hosting, and I've been pleased with their service thus far. If anyone has a better suggestion, I'm all ears.

    <object width="800" height="490"> <param name="allowfullscreen" value="true" /> <param name="allowscriptaccess" value="always" /> <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=1642150&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" /> <embed src="http://vimeo.com/moogaloop.swf?clip_id=1642150&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="800" height="490"></embed></object><br /><a href=" ">iPhone Tutorial - UIScrollViews with pinch/zooming</a> from <a href="http://vimeo.com/user647705?pg=embed&sec=1642150">Nick Myers</a> on <a href="http://vimeo.com?pg=embed&sec=1642150">Vimeo</a>.
    <a href=http://www.vimeo.com/download/video:85049636?e=1220544094&h=dc12c612c984ee803535865c1dcd3675>Download the HiDef version to your computer</a>
    · ·
Sign In or Register to comment.