Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-12-2011, 03:58 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default Random Image via UIScrollView

I have two UIScrollViews in my app, each with it's own unique set of images (scroll left/right to view them).

I want to be able to tap my UIBarButtonItem and it will create the effect of each scroll view autoscrolling and then each selecting a random image.

Does anyone know of a tutorial on this or can give me an explanation of how to go about this?


Thanks!
lukeirvin is offline   Reply With Quote
Old 10-12-2011, 10:22 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Just generate a random number from 0 to however-many-images-you-have-minus-one, and then animate the scrollview to the point equal (scrollview width * random number). Scrollviews have methods for that so check the documentation.
baja_yu is offline   Reply With Quote
Old 10-13-2011, 01:20 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

I'm using this and it's working fine:

Code:
- (IBAction)mixButtonTapped:(id)sender
{
    if (arc4random() % kNumImagesTops && arc4random() % kNumImagesBottoms) 
    {
        [topsScrollView setContentOffset:CGPointMake(320, 0) animated:YES];
        [bottomsScrollView setContentOffset:CGPointMake(320, 0) animated:YES];
    }
}
My next problem is creating an Infinite Scroll.

Is this based on how you adjust the width alone or specifying how the images will be placed?
lukeirvin is offline   Reply With Quote
Old 10-13-2011, 02:05 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Why would you need an infinite scroll? Just asking because if you're taking a random image then there must be a finite number of images.

As a side note, there's an infinite scroll sample code called StreetScroller in the docs, but it requires the latest Xcode and SDK, not sure why, haven't tried it yet.
baja_yu is offline   Reply With Quote
Old 10-13-2011, 04:31 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Once this project is completed there will be a lot of images.

I'm not sure if an infinite scroll is really needed but I'd like to implement it.

Right now though it's not selected a random image, it's going to the last image.

Based on my code posted can anyone see why?

I have been working with Apple's sample code some today. I just can't get it working for images yet.
lukeirvin is offline   Reply With Quote
Reply

Bookmarks

Tags
image, random, scroll, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 403
16 members and 387 guests
13dario13, 7twenty7, buggen, eski, EvilElf, glenn_sayers, LunarMoon, morterbaher, n00b, pbart, QuantumDoja, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0