iphone - change orientation dynamically -


i want change view layout dynamically. how define in code? in code define as

const cgfloat kscrollobjheight    = 460.0; const cgfloat kscrollobjwidth    = 320.0; const nsuinteger knumimages        = 32;  - (void)layoutscrollimages {     uiimageview *view = nil;     nsarray *subviews = [scrollview1 subviews];      // reposition image subviews in horizontal serial fashion     cgfloat curxloc = 0;     (view in subviews)     {         if ([view iskindofclass:[uiimageview class]] && view.tag > 0)         {             cgrect frame = view.frame;             frame.origin = cgpointmake(curxloc, 0);             view.frame = frame;              curxloc += (kscrollobjwidth);         }     }      // set content size can scrollable     [scrollview1 setcontentsize:cgsizemake((knumimages * kscrollobjwidth), [scrollview1 bounds].size.height)]; }  - (void)viewdidload {     self.view.backgroundcolor = [uicolor viewflipsidebackgroundcolor];      // 1. setup scrollview multiple images , add view controller     //     // note: following can done in interface builder, show in code clarity     [scrollview1 setbackgroundcolor:[uicolor blackcolor]];     [scrollview1 setcancancelcontenttouches:no];     scrollview1.indicatorstyle = uiscrollviewindicatorstylewhite;     scrollview1.clipstobounds = yes;        // default no, want restrict drawing within our scrollview     scrollview1.scrollenabled = yes;      //imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"image0.jpg"]];     [scrollview1 addsubview:imageview];     [scrollview1 setcontentsize:cgsizemake(imageview.frame.size.width, imageview.frame.size.height)];     scrollview1.minimumzoomscale = 1;     scrollview1.maximumzoomscale = 3;     scrollview1.delegate = self;     [scrollview1 setscrollenabled:yes];      // pagingenabled property default no, if set scroller stop or snap @ each photo     // if want free-flowing scroll, don't set property.     scrollview1.pagingenabled = yes;      // load images our bundle , add them scroll view     nsuinteger i;     (i = 1; <= knumimages; i++)     {         nsstring *imagename = [nsstring stringwithformat:@"page-%d.jpg", i];         uiimage *image = [uiimage imagenamed:imagename];         uiimageview *imageview = [[uiimageview alloc] initwithimage:image];          // setup each frame default height , width, placed when call "updatescrolllist"          cgrect rect = imageview.frame;         rect.size.height = kscrollobjheight;         rect.size.width = kscrollobjwidth;         imageview.frame = rect;         imageview.tag = i;    // tag our images later use when place them in serial fashion         [scrollview1 addsubview:imageview];         [imageview release];     }      [self layoutscrollimages];    // place photos in serial layout within scrollview   }  -(uiview *) viewforzoominginscrollview:(uiscrollview *)scrollview {     return imageview; }   - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation {      return yes; }   - (void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration {      [super willrotatetointerfaceorientation:tointerfaceorientation duration:duration];       switch(tointerfaceorientation){         case (uiinterfaceorientationlandscapeleft):         {             landscapemodeviewcontroller=[[landscapemodeviewcontroller alloc] initwithnibname:@"landscapemodeviewcontroller" bundle:nil];             [self.view addsubview:landscapemodeviewcontroller.view];             /*uialertview *info = [[uialertview alloc] initwithtitle:@"info" message:@"change mode" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];             [info show];             [info release];*/         }             break;         case(uiinterfaceorientationlandscaperight):         {             //landscapemodeviewcontroller=[[landscapemodeviewcontroller alloc] initwithnibname:@"landscapemodeviewcontroller" bundle:nil];             //[self.view addsubview:landscapemodeviewcontroller.view];             uialertview *info = [[uialertview alloc] initwithtitle:@"info" message:@"change mode" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];             [info show];             [info release];         }             break;         case(uiinterfaceorientationportrait):         {             //portraitmode=[[portraitmode alloc] initwithnibname:@"portraitmode" bundle:nil];             //[self.view addsubview:portraitmode.view];             uialertview *info = [[uialertview alloc] initwithtitle:@"info" message:@"change mode" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];             [info show];             [info release];          }             break;              /*if(tointerfaceorientation == uiinterfaceorientationlandscapeleft || tointerfaceorientation == uiinterfaceorientationlandscaperight) {              uialertview *info = [[uialertview alloc] initwithtitle:@"info" message:@"select landscape mode." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];              [info show];              [info release];              [scrollview1 release];              landscapemodeviewcontroller=[[landscapemodeviewcontroller alloc] initwithnibname:@"landscapemodeviewcontroller" bundle:nil];              [self.view addsubview:landscapemodeviewcontroller.view];                }                else{              uialertview *info = [[uialertview alloc] initwithtitle:@"info" message:@"select portrait mode" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil];              [info show];              [info release];               portraitmode=[[portraitmode alloc] initwithnibname:@"portraitmode" bundle:nil];              [self.scrollview1 addsubview:portraitmode.view];              }  */         } } - (void)dealloc {         [scrollview1 release];     [imageview release];      [super dealloc]; }  - (void)didreceivememorywarning {      [super didreceivememorywarning]; }  @end 

in above code when rotate device uialerview execute previous view not release , landsacpe mode shown behind him. that?

you can set autoresize mask each view in layout in whatever manner want.

for example, if want button show on top left corner, can set auto resize mask flexible top , left..

if layout totally different in portrait , landscape, need set frames in willrotatetointerfaceorientation.

for example if want button on top left in portrait , in center in landscape, need set frame in above delegate method.

edit answer:

 if(uiinterfaceorientationislandscape(tointerfaceorientation)){     if(!landscapemodeviewcontroller){          landscapemodeviewcontroller=[[landscapemodeviewcontroller alloc] initwithnibname:@"landscapemodeviewcontroller" bundle:nil];     }     [self.view addsubview:landscapemodeviewcontroller.view];     [self.view bringsubviewtofront:landscapemodeviewcontroller.view];  }  else if(uiinterfaceorientationisportrait(tointerfaceorientation)){      if(!portraitmode){          portraitmode=[[portraitmode alloc] initwithnibname:@"portraitmode" bundle:nil];      }      [self.view addsubview:portraitmode.view];      [self.view bringsubviewtofront:portraitmode.view];  } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -