Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SponsorBannerView.m
- // CPOP Test 4
- //
- // Created by Will Kerswell on 07/01/2013.
- // Copyright (c) 2013 Will Kerswell. All rights reserved.
- //
- #import "SponsorBannerView.h"
- #import <QuartzCore/QuartzCore.h>
- @implementation SponsorBannerView{
- int currentImage;
- NSTimer *nextImgTimer;
- }
- @synthesize bannerImage;
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect{
- //get the sponsors banners and id's.
- DataBase * dataBase = [[DataBase alloc] init];
- [dataBase openDB];
- NSMutableDictionary *BannersAndId = [dataBase getBanners];
- //create an id array and a banner array.
- self.poiIDs = [BannersAndId allKeys];
- self.banners = [BannersAndId allValues];
- //get the root file path for the images
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- //create an array to hold the image
- NSMutableArray * images = [[NSMutableArray alloc]init];
- //create an array containing all the images
- for (int i = 0; i<self.banners.count; i++) {
- NSString *tmp = [NSString stringWithFormat:@"%@/%@",documentsDirectory, self.banners[i]];
- UIImage * tmpIamge = [UIImage imageWithContentsOfFile:tmp];
- [images addObject:tmpIamge];
- }
- //cast the mutable array into an array
- self.banners = [NSArray arrayWithArray:images];
- [self nextImageFade];
- //set all the banner settings
- bannerImage=[[UIImageView alloc]init];
- bannerImage.frame=CGRectMake(0, 0, 320, 50);
- [bannerImage setAnimationImages:self.banners];
- [bannerImage setAnimationDuration:8];
- [bannerImage setAnimationRepeatCount:0];
- [bannerImage startAnimating];
- //add to view.
- [self addSubview:bannerImage];
- // add a uibutton on top of the uiimageview and assign an action for it
- UIButton* actionButton=[UIButton buttonWithType:UIButtonTypeCustom];
- actionButton.frame=CGRectMake(0, 0, 320, 50);
- [actionButton addTarget:self action:@selector(sponsorBannerAction) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:actionButton];
- }
- -(void) sponsorBannerAction{
- // do what ever here like going to an other uiviewController as you mentionned
- NSLog(@"Pressed");
- }
- - (void)nextImageFade{
- UIImage *image1 = [UIImage imageNamed:[self.banners objectAtIndex:currentImage]];
- if(currentImage < [self.banners count]-1){
- currentImage++;
- }else{
- currentImage = 0;
- }
- UIImage *image2 = [UIImage imageNamed:[self.banners objectAtIndex:currentImage]];
- CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
- crossFade.delegate = self;
- crossFade.duration = 0.5;
- crossFade.fromValue = (id)image1.CGImage;
- crossFade.toValue = (id)image2.CGImage;
- [_imgView1.layer addAnimation:crossFade forKey:@"animateContents"];
- _imgView1.image = image2;
- //This this may work for changing targets
- [actionButton addTarget:self action:@selector([methodArray objectAtIndex:CurrentImg]) forControlEvents:UIControlEventTouchUpInside];
- if(nextImgTimer != nil){
- [nextImgTimer invalidate];
- }
- nextImgTimer = [NSTimer scheduledTimerWithTimeInterval:5
- target:self
- selector:@selector(nextImageFade)
- userInfo:nil
- repeats:NO];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement