Log in or register to post comments

How to properly deal with rotations?

April 4, 2013 - 5:51am #1

Hi,

I have some GUI of my own inside CROverlayViewController and one starting screen inside CRParentViewController. What is the proper way, to place GUI elements depending on device rotation? Now I have that starting CloudReco sample using push segue (storyboard in use), whatever is orientation in app menu, CloudReco itself is starting with the same as menu and GUI looks good (corner images are in fact in corners). However GUI looks good before rotation, after it's a mess. If you change from portrait to landscape inside CloudReco part all elements that were below certain height will not be shown after rotation to landscape...

Only rotation code of CRParentViewController is called:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    //  Since CRParentViewController does not inherit from BaseViewController,
    //  we have to override this behavior
    
    BOOL retVal = [[CRQCARutils getInstance] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    return retVal;
//    return YES;
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    NSLog(@"CRPVC: didRotateFromInterfaceOrientation");
    [UIView animateWithDuration:0.5 animations:^{
        [startView setCenter:self.view.center];
    }];
}

but CROverlayViewController not:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    NSLog(@"CROVC: shouldAutorotate");
    //  Since CRParentViewController does not inherit from BaseViewController,
    //  we have to override this behavior
    BOOL retVal = [[CRQCARutils getInstance] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    return retVal;
//    return YES;
}

What's more, animating startView makes it move from ealier center to the newer one. I wish I could make all elements stay on their place.

 

Here are logs from rotations: (VC stands for ViewController ;) )

2013-04-04 14:49:51.593 CloudReco[1046:707] OVC: handleViewRotation
2013-04-04 14:49:51.595 CloudReco[1046:707] CRVC: handleARViewRotation
2013-04-04 14:49:51.597 CloudReco[1046:707] CRVC: Rotating to Landscape Left
2013-04-04 14:49:51.600 CloudReco[1046:707] EAGLView: layoutSubviews
2013-04-04 14:49:51.604 CloudReco[1046:707] EAGLView: initRendering
2013-04-04 14:49:51.913 CloudReco[1046:707] CRPVC: didRotateFromInterfaceOrientation

 

How to properly deal with rotations?

April 11, 2013 - 11:12am #11

You need to add this to CRParentViewController.h

 

@property (nonatomic) CGSize arViewSize;

and synthesize in the .m file

 

@synthesize arViewSize;

Sorry - not in a position to be able to post up a sample project, but happy to help.

 

N

How to properly deal with rotations?

April 11, 2013 - 7:57am #10

Didn't work :/ this part was faulty: _cameraViewController.arViewSize = self.view.bounds.size;

Could you post the "primitive" cloud reco sample with storyboards on some github or something? I'm sure that many would've found it useful, like Danchoy's example with ImageTargets :) it's really annoying not to be able to deal with such a basic stuff like view sizes. rotations etc :(

How to properly deal with rotations?

April 10, 2013 - 8:35am #9

This is something I cooked up in order to help answer questions like this :)

The problem with using segues in this instance is that it creates a new ViewController which is exactly what we do not want, because we only want to initialise Vuforia once due to the init / deinit issues.  Instead you have to push the existing CameraViewController which is created only once

So I have a VC with a go button as below:

HEADER

 

#import <UIKit/UIKit.h>

 

@class CRParentViewController;

 

@interface StartViewController : UIViewController

- (IBAction)goButton:(id)sender;

 

@property (strong, nonatomic) CRParentViewController *cameraViewController;

 

@end

SOURCE

 

#import "StartViewController.h"

#import "CRParentViewController.h"

 

@implementation StartViewController

@synthesize cameraViewController = _cameraViewController;

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    _cameraViewController = [[CRParentViewController alloc] initWithNibName:nil bundle:nil];

 

    // need to set this so subsequent view controllers know the size 

    _cameraViewController.arViewSize = self.view.bounds.size;

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)dealloc

{

    [_cameraViewController release];

    [super dealloc];

}

 

 

- (IBAction)goButton:(id)sender {

 

    [self.navigationController pushViewController:_cameraViewController animated:YES];

}

 

@end

 

When the user presses Go, it triggers the cameraViewController.

HTH

N

 

 

 

 

How to properly deal with rotations?

April 10, 2013 - 7:56am #8

Thanks a lot, looks good :) where did you get this storyboard version ? do you have it to check segues and stuff? Maybe my fault is in connections, anyway love to see this "pro storyboard" CloudReco :)

p.s. I'll use next time "attach" ;)

How to properly deal with rotations?

April 10, 2013 - 7:13am #7

It is preferrable to use the in-built mechanism, rather than third party hosting services because sometime it is not clear whether you need to wait etc.

Either way I have attached two images of CloudReco adapted to run inside a storyboard - one portrait and one landscape.  In both situations the close button appears in the top right.

This uses the standard built in code with no additional modifications.

 

Is this what you are after?

Not quite clear what is happening in your pictures, but it seems not to be rotating the UI at all.

 

N

AttachmentSize
Image icon IMG_0063.PNG944.85 KB
Image icon IMG_0064.PNG957.81 KB

How to properly deal with rotations?

April 9, 2013 - 3:30pm #6

seemed lot faster and easier, didn't you take a look a those links? 

How to properly deal with rotations?

April 9, 2013 - 7:45am #5

Any chance you can attach these files here using the new "attach" functionality on posts?

N

How to properly deal with rotations?

April 9, 2013 - 7:39am #4

Btw, the UILabel with pointing device hint I have added to CRParentViewController (because tapped it should start Vuforia) and rest has been added in CROverlayViewController.

How to properly deal with rotations?

April 9, 2013 - 7:36am #3

Here you go,

http://speedy.sh/UHJSV/IMG-1007.PNG
http://speedy.sh/jgeYE/vuforia-landscape.PNG
http://speedy.sh/bjXaM/vuforia-portrait.PNG

on part is staying in portrait while the rest is going to landscape nad my views are not updating to proper sizes, though I'm doing it for every rotation. The last link is what it more or less looks like in portrait and I expect to achieve similar effects in landscape mode, so corner images will be still in corners and buttons I added at the bottom in portrait so they will rotate with screen and stay still at the bottom of the screen despite the orientation of screen...

How to properly deal with rotations?

April 5, 2013 - 10:18am #2

This is hard to visualise:

However GUI looks good before rotation, after it's a mess. If you change from portrait to landscape inside CloudReco part all elements that were below certain height will not be shown after rotation to landscape

Could you possibly post up some pictures to show what is happening?

thanks

N

 

 

 

 

Log in or register to post comments