我花了一段时间环顾四周,但似乎找不到太多关于这个主题的东西。我想制作一个像 iAd 一样的横幅,但用于我自己的应用内广告。广告会将用户带到应用程序内的视图。
这是我为展示广告横幅所做的设计。
到目前为止,我所做的事情有两个问题。
1)我想自定义图像的顺序。
我想要一个主广告,然后是子广告。主要广告应该首先播放,其他所有图片都应该是主要广告。那么子广告的顺序应该是随机的。我怎么能做到这一点?我可以使用当前的即时动画方式来完成它还是会有更好的解决方案?
2)我不知道如何将图像链接到不同的地方。
到目前为止,我拥有它,因此所有图像都运行相同的操作。我怎样才能让他们改变不同的观点?
这就是我到目前为止所拥有的。
@implementation SponsorBannerView{
}
@synthesize bannerImage;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect{
//get the sponsors banners and id's.
DataBase * dataBase = [[DataBase alloc] init];
[dataBase openDB];
NSMutableDictionary *BannersAndId = [dataBase getBanners];
NSLog(@"banner and id's : %@",BannersAndId);
//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
NSArray *array = [NSArray arrayWithArray:images];
//set all the banner settings
bannerImage=[[UIImageView alloc]init];
bannerImage.frame=CGRectMake(0, 0, 320, 50);
bannerImage.backgroundColor=[UIColor purpleColor];
[bannerImage setAnimationImages:array];
[bannerImage setAnimationDuration:6];
[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");
}
这是我作为主视图的子视图添加的视图。
任何帮助都会很棒。谢谢