UIWebViewを9枚のパネルにして並べてみる
(XcodeのiOS6 Simulatorで試しています。)
ポイント
・webViewのレンダリング中はalphaを0にして中央に
・Viewの縮小はtransformで設定する
サンプルコード
#import “ViewController.h”
@interface ViewController () {
NSTimer *timer;
}
@property (nonatomic, strong) NSMutableArray *pages;
@end
@implementation ViewController
@synthesize pages;
– (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
UILabel *loading = [[UILabel alloc] init];
loading.font = [UIFont boldSystemFontOfSize:30];
loading.textColor = [UIColor whiteColor];
loading.text = @”now loading…”;
loading.backgroundColor = [UIColor clearColor];
[loading sizeToFit];
loading.center = self.view.center;
[self.view addSubview:loading];
[UIView animateWithDuration:6 animations:^{
loading.alpha = 0.0;
} completion:^(BOOL finished) {
[loading removeFromSuperview];
}];
pages = [[@”http://www.google.com http://www.takaratomy.co.jp/products/tomica/ http://www.disney.co.jp/home.html http://www.lego.com http://www.apple.com http://amazon.com http://www.toysrus.com https://twitter.com http://www.microsoft.com” componentsSeparatedByString:@” “] mutableCopy];
for (int i=0; i<[pages count]; i++) {
[self createPage:i];
}
}
– (void)createPage:(int)number
{
NSString *add = [pages objectAtIndex:number];
NSURL *url = [NSURL URLWithString:add];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
UIWebView *v = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
v.alpha = 0.0;
v.transform = CGAffineTransformMakeScale(0.7, 0.7);
[v loadRequest:requestObj];
[self.view addSubview:v];
float time = 5.0 + 1.0 * number;
[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(layout:) userInfo:v repeats:NO];
}
– (void)layout:(NSTimer *)sender
{
UIWebView *webView = sender.userInfo;
static int counter;
float x = 50 + 106 * (counter % 3);
float y = 70 + 140 * (counter / 3);
[UIView animateWithDuration:0.5 animations:^{
webView.alpha = 1.0;
webView.transform = CGAffineTransformMakeScale(0.3, 0.3);
webView.center = CGPointMake(x, y);
}];
counter++;
}
– (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end