简体   繁体   中英

UIView transitionFromView:toView with two tableview controllers - strange location bug

I have

UIButton *home = [UIButton buttonWithType:UIButtonTypeContactAdd];
[home addTarget:self action:@selector(addNewRoute:) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc]
                                  initWithCustomView:home] autorelease];
self.navigationItem.rightBarButtonItem = cancelButton;
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.15 green:0.15 blue:0.49 alpha:1.0];

which do rotate:

- (void) addNewRoute:(id) sender
    {
       if (!routeAddIsActive) {
            [UIView transitionFromView:self.addRoutesView.view toView:self.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft  completion:nil];
        } else {
            [UIView transitionFromView:self.view toView:self.addRoutesView.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft  completion:nil];
        }
        routeAddIsActive = !routeAddIsActive;

    }

here is a view for rotation:

if (!addRoutesView) {
    addRoutesView = [[AddRoutesTableViewController alloc] initWithStyle:UITableViewStylePlain];
    addRoutesView.managedObjectContext = self.managedObjectContext;
}

when i start a rotation from view:

在此处输入图像描述

i have a strange change for new UIView position: looks like iphone decide to move down view. Returning is ok, everything work fine.

在此处输入图像描述

UPDATE Now i have problem out by this code:

setup view:

if (!addRoutesView) {
    addRoutesView = [[AddRoutesTableViewController alloc] initWithStyle:UITableViewStylePlain];
    addRoutesView.destinationsPushListView = self;
    addRoutesView.managedObjectContext = self.managedObjectContext;
    if (!addRoutesNavigationView) {
        addRoutesNavigationView = [[UINavigationController alloc] initWithRootViewController:addRoutesView];

change view in destinationsPushListView

- (void) addNewRoute:(id) sender
{
self.addRoutesNavigationView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addRoutesNavigationView animated:YES];

change view in addRoutesView

- (void) addNewRoute:(id) sender
{
self.destinationsPushListView.navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:destinationsPushListView.navigationController animated:YES];

Everything work fine, view changed, all correct, changed back, and then, when i clicked again, function addNewRoute called, and application stop and freeze without any errors and logs. I have to keep navigation bar inside, this is maybe a best way to control rotate.

To directly answer your question, check your frames. transitionFromView: shouldn't move anything around, so try switching the views without it, and check that everything line up.

Also, it looks like you are adding the view of another view controller to your current view controller. You may want to consider using a modal view controller with a flip animation. To do that all you need to do is modify your flip to

addRoutesView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addRoutesView animated:YES];

You would then also need to implement some delegate or notification setup to flip back around. If you plan to go that route there is some good documentation on it here http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM