iOS_Passion
iOS_Passion

Reputation: 788

IOS Scrollview Marquee style

I have a set of 4 images that i want to show in a UIScrollView. This scroll view contains ad banners. So they have to keep scrolling vertically down automatically similar to marquee effect - user does not need to touch the screen to scroll.This process should keep repeating.

If the user touches the screen, the scrolling should stop & when user re-touches the screen the scrolling should restart from where it had left.

Upvotes: 1

Views: 1166

Answers (3)

dokun1
dokun1

Reputation: 2110

I made an API for this, if you're interested.

https://github.com/dokun1/DOMarqueeLabel

Upvotes: 0

iOS_Passion
iOS_Passion

Reputation: 788

This is how I have done it finally :-) .
Call the below method from viewDidLoad

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollTheScrollView) userInfo:nil repeats:YES];

Now implement the method

-(void)scrollTheScrollView{

static int i=0;

i++;

if(self.scrollView.contentOffset.y == 700.0)//This 700.0 will be different for you
    i=0;

NSLog(@"Content offset in scrolling method is %@",self.scrollView);

[self.scrollView setContentOffset:CGPointMake(0, i*5)];}

Upvotes: 1

Bhavin
Bhavin

Reputation: 27225

There is as simpler way, I guess. UIImageView can help you. Follow these Steps :

1) Add 4 UIImageViews Vertically Down.

2) Create 4 Different Arrays for these ImageViews.

NSArray *frames1 = [NSArray arrayWithObjects:[UIImage imageWithName:@"a.png"],[UIImage imageWithName:@"b.png"],[UIImage imageWithName:@"c.png"],[UIImage imageWithName:@"d.png"],nil];
NSArray *frames2 = [NSArray arrayWithObjects:[UIImage imageWithName:@"b.png"],[UIImage imageWithName:@"c.png"],[UIImage imageWithName:@"d.png"],[UIImage imageWithName:@"a.png"],nil];
NSArray *frames3 = [NSArray arrayWithObjects:[UIImage imageWithName:@"c.png"],[UIImage imageWithName:@"d.png"],[UIImage imageWithName:@"a.png"],[UIImage imageWithName:@"b.png"],nil];
NSArray *frames4 = [NSArray arrayWithObjects:[UIImage imageWithName:@"d.png"],[UIImage imageWithName:@"a.png"],[UIImage imageWithName:@"b.png"],[UIImage imageWithName:@"c.png"],nil];

3) Provide these Arrays to all these different ImageViews.

yourImageView1.animationImages = frames1;
yourImageView2.animationImages = frames2;
yourImageView3.animationImages = frames3;
yourImageView4.animationImages = frames4;

4) You can add some Effects also...

// all frames will execute in 1.75 seconds
yourImageView.animationDuration = 1.75;
// repeat the annimation forever
yourImageView.animationRepeatCount = 0;

5) Simply startAnimating the ImageViews.

[yourImageView1 startAnimating]; 
[yourImageView2 startAnimating]; 
[yourImageView3 startAnimating]; 
[yourImageView4 startAnimating]; 

6) You can always use -touchesEnded method to start and stop Animation.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([[touches anyObject] view] == yourImageView1) {
        //Here you can write the code to stop and start Animation of UIImageView
    }
}

I think this will give you the effect what you want.

GoodLuck !!!

Upvotes: 1

Related Questions