私はしばらく周りを見回してきましたが、この件についてはあまり見つけられないようです。iAd のようなバナーを自分のアプリ内広告用に作成したいと考えています。広告により、ユーザーはアプリ内のビューに移動します。
これは、広告バナーを表示するために作成したデザインです。
私がこれまでやってきたことには2つの問題があります。
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");
}
これは、メイン ビューのサブ ビューとして追加したビューです。
どんな助けでも素晴らしいでしょう。ありがとう