・縦横それぞれのUIViewを作ってUILabelにaddSubView。
・各viewにtagを貼る。縦は1000000+ポストNo.、横は2000000+ポストNo.。百万件掘る人がいたら再考する。
・rootのvcで回転を検知するたびに片方のviewのhiddenをYESにする。
・ボタンのcgrectを参照してrootのvcから縦横2つのviewに貼るのは面倒かつ醜いのでpostのviewが自前で貼るようにして、メッセージをrootのvcで受けるようにdelegateを使う。(初挑戦)
・viewDidLoadでself.view.boundsが呼ばれるたびに現状のウィンドウを取得すると思ってたらviewDidAppearでやらんとダメということを知ったので改修。
とりあえずこれで動いてる様子。
rootのvc
- (void)mkSinglePostView{
for(int i=[pvArr count];i<[contArr count];i++){
postv=[[SinglePost2 alloc]init];postv.delegate=self;
[postv constructWithtype:[typeArr objectAtIndex:i] cont:[contArr objectAtIndex:i] bnamet:[bnameArr objectAtIndex:i] now:i+1];
[naxArr addObject:postv.nax];
if(postv.linkurl)[openArr insertObject:postv.linkurl atIndex:i];
[postv.view setTag:i+1];
[pvArr addObject:postv.view];
}
[pvlayer.view addSubview:[pvArr objectAtIndex:now-1]];[pvlayer.view setFrame:self.view.bounds];
if(!now_all) now_all=[[UILabel alloc]init];[self na];
if(!caption) caption=[[UILabel alloc]init];[self mkCaption];
}
-(void)reflink{
if([[typeArr objectAtIndex:now-1]isEqual:@"link"]){
if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
[self.view viewWithTag:1000000+now].hidden=YES;[self.view viewWithTag:2000000+now].hidden=NO;
}else{
[self.view viewWithTag:1000000+now].hidden=NO;[self.view viewWithTag:2000000+now].hidden=YES;
}
}
}
SinglePost2.m
}else if([type isEqualToString:@"link"]){
_linkurl=[cont objectAtIndex:1];
for(int pl=0;pl<2;pl++){
Link *link=[[Link alloc]initWithFrame:CGRectMake(10,30,(pl?sh:sw)-20,(pl?sw:sh)-80)
string:[[cont objectAtIndex:0]isEqual:[NSNull null]]||[[cont objectAtIndex:0]isEqual:@""]?@"(no text)":[cont objectAtIndex:0]];
UIImage *openlinkimg=[UIImage imageNamed:@"openlink"],*openlinkimg_on=[UIImage imageNamed:@"openlink_on"];
UIButton *open=[UIButton buttonWithType:UIButtonTypeCustom];
[open setImage:openlinkimg forState:UIControlStateNormal];[open setImage:openlinkimg_on forState:UIControlStateHighlighted];
[open addTarget:delegate action:@selector(openPage) forControlEvents:UIControlEventTouchUpInside];
[open setFrame:CGRectMake(10,(pl?sw:sh)-link.origin.y-30,openlinkimg.size.width,openlinkimg.size.height)];
UIView *lv=[[UIView alloc]initWithFrame:CGRectMake(0,0,pl?sh:sw,pl?sw:sh)];
[lv addSubview:link];[lv addSubview:open];[lv setTag:(pl?2000000:1000000)+now];
if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){if(!pl)lv.hidden=YES;}
else if(pl)lv.hidden=YES;
[self.view addSubview:lv];
}
}
OpenPage.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
page=[[UIWebView alloc]initWithFrame:self.view.bounds];page.scalesPageToFit=YES;page.delegate=self;page.autoresizingMask=18;[self.view addSubview:page];
toolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height-36, self.view.bounds.size.width,36)];
toolbar.tintColor=[UIColor blackColor];toolbar.translucent=YES;
[self.view addSubview:toolbar];toolbar.autoresizingMask=42;
back=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(back)];
forward=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(forward)];
done=[[UIBarButtonItem alloc]initWithTitle:@"done" style:UIBarButtonItemStyleDone target:self action:@selector(killme)];
NSArray *buttons=[[NSArray alloc]initWithObjects:done,back,forward,nil];
[toolbar setItems:buttons animated:YES];
[page loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
できた。あとはchat,audio,video,answerの回転対応。余裕やと思ってたけどまだまだベーシックな部分で理解と知識が足りてない。
0 件のコメント:
コメントを投稿