方法一、横屏竖屏时分别加载两个不同的vIEw,手写vIEw
-(voID)willAnimateRotationToInterfaceOrIEntation:(UIInterfaceOrIEntation)toInterfaceOrIEntation duration:(NSTimeInterval)duration{ if (UIInterfaceOrIEntationIsPortrait(toInterfaceOrIEntation)) { [landscape removeFromSupervIEw]; [self.vIEw addSubvIEw:portrait]; } if (UIInterfaceOrIEntationIsLandscape(toInterfaceOrIEntation)) { [portrait removeFromSupervIEw]; [self.vIEw addSubvIEw:landscape]; }}// Implement loadVIEw to create a vIEw hIErarchy programmatically,without using a nib.- (voID)loadVIEw { UIControl *back = [[UIControl alloc] initWithFrame:[[UIScreen mainScreen]bounds]]; back.backgroundcolor = [UIcolor graycolor]; self.vIEw = back; [back release]; }// Implement vIEwDIDLoad to do additional setup after loading the vIEw,typically from a nib.- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; portrait = [[UIVIEw alloc] initWithFrame:CGRectMake(10,10,300,440)]; portrait.backgroundcolor = [UIcolor yellowcolor];// [portrait addbutton]; landscape = [[UIVIEw alloc] initWithFrame:CGRectMake(10,460,280)]; landscape.backgroundcolor = [UIcolor greencolor]; [self.vIEw addSubvIEw:portrait]; }// OverrIDe to allow orIEntations other than the default portrait orIEntation.- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation { // Return YES for supported orIEntations. NSLog(@"heheh"); return NO; }
方法二、在一个XIB里面添加两个不同的vIEw,只用改变两个不同vIEw里面控件尺寸,动作事件是一样的
-(voID)willAnimateRotationToInterfaceOrIEntation:(UIInterfaceOrIEntation)toInterfaceOrIEntation duration:(NSTimeInterval)duration{ if (UIInterfaceOrIEntationIsPortrait(toInterfaceOrIEntation)) { [self.landscapeVIEw removeFromSupervIEw]; [self.vIEw addSubvIEw:self.portraitVIEw]; } if (UIInterfaceOrIEntationIsLandscape(toInterfaceOrIEntation)) { [self.portraitVIEw removeFromSupervIEw]; [self.vIEw addSubvIEw:self.landscapeVIEw]; }}- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; [self.vIEw addSubvIEw:self.portraitVIEw]; }总结
以上是内存溢出为你收集整理的IOS横屏竖屏问题---2全部内容,希望文章能够帮你解决IOS横屏竖屏问题---2所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)