iphone - iOS: Not being able to resize frames in modal view when in landscape mode -


i have uiviewcontroller contains uicollectionview. on clicking on of uicollectionviewcell show detailed contents of cell in modal view. have added objects (uilabel, uiimage etc.) in modal view through storyboard. resize frames when device orientation changed using nsnotificationcenter:

in viewdidload method of modal controller:

[[uidevice currentdevice] begingeneratingdeviceorientationnotifications]; nsnotificationcenter* notifcenter = [nsnotificationcenter defaultcenter]; [notifcenter addobserver:self selector:@selector(orientationchanged) name:uideviceorientationdidchangenotification object:nil]; 

orientationchanged content:

-(void) orientationchanged {     if (uideviceorientationislandscape([[uiapplication sharedapplication] statusbarorientation])) {         self.productimage.frame = cgrectmake(61, 5, 124, 138);         self.sitelogo.frame = cgrectmake(61, 146, 124, 90);         self.productname.frame = cgrectmake(220, 5, 150, 102);         self.productprice.frame = cgrectmake(220, 120, 124, 21);     }     else {         self.productimage.frame = cgrectmake(61, 5, 124, 138);         self.sitelogo.frame = cgrectmake(61, 146, 124, 90);         self.productname.frame = cgrectmake(20, 244, 207, 102);         self.productprice.frame = cgrectmake(61, 354, 124, 21);     } } 

now when start app in portrait mode , click of of uicollectionviewcell modal view shows correctly, when change landscape mode (without dismissing modal view) able resize frames due above method.

problem when start app in landscape mode , click on uicollectionviewcell modal view shows in portrait mode. want in landscape mode correctly resizing frames. tried setting frames in viewdidlayoutsubviews & in viewdidappear of no use.

content of viewdidlayoutsubviews:

-(void)viewdidlayoutsubviews{     self.productimage.autoresizingmask = 0;     self.productprice.autoresizingmask = 0;     self.productname.autoresizingmask = 0;     self.sitelogo.autoresizingmask = 0;     if (uideviceorientationislandscape([[uiapplication sharedapplication] statusbarorientation])) {         self.productimage.frame = cgrectmake(61, 5, 124, 138);         self.sitelogo.frame = cgrectmake(61, 146, 124, 90);         self.productname.frame = cgrectmake(220, 5, 150, 102);         self.productprice.frame = cgrectmake(220, 120, 124, 21);     }     else {         self.productimage.frame = cgrectmake(61, 5, 124, 138);         self.sitelogo.frame = cgrectmake(61, 146, 124, 90);         self.productname.frame = cgrectmake(20, 244, 207, 102);         self.productprice.frame = cgrectmake(61, 354, 124, 21);     } } 

thanks in advance.

as per https://stackoverflow.com/a/12555205/667586

modal viewcontrollers no longer rotation calls in ios 6: willrotatetointerfaceorientation:duration:, willanimaterotationtointerfaceorientation:duration:, , didrotatefrominterfaceorientation: methods no longer called on view controller makes full-screen presentation on itself—for example called with: presentviewcontroller:animated:completion:.

you can let view controller presents modal view controller inform of rotation. also, use: presentviewcontroller:animated:completion: present view controller. presentmodalviewcontroller:animated: deprecated use in code.

write code : in modal view controller :

// returns interface orientation masks. - (uiinterfaceorientation)preferredinterfaceorientationforpresentation ns_available_ios(6_0){ return uiinterfaceorientationlandscapeleft; } 

in calling view controller :

myvc *webvc = [[myvc alloc] init]; [self.navigationcontroller presentviewcontroller:myvc animated:yes completion:^{     [myvc shouldautorotate]; }]; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -