2014-02-06 17 views
0

我正在创建一个应用程序,用户可以在其中尝试不同的眼镜。更新视图控制器而不替换所有内容

mainView控制器有两个IUImageViews(照片和眼镜)。这个视图控制器也有两个按钮,(拍照和选择照片)。一旦用户轻扫或点击导航按钮,就会出现侧面导航,用户可以选择一副眼镜来尝试。

但是,只有在用户选择了一副眼镜时,才能使用或选择照片而不是其他方式,因为当选择一副眼镜时照片会被完全覆盖。

这使我想知道如何以及如果我可以允许它,所以视图不会被覆盖,所以如果用户拍摄照片,然后选择一副眼镜,照片会留在那里,然后这副眼镜会出现太。

现在到当前代码:

的每一副眼镜具有上的导航按钮,这是其中一个按钮的一个例子...

- (IBAction)glass_one_pressed:(id)sender{ 
[self performSegueWithIdentifier:@"imageChangeSegue" sender:nil];} 

的赛格瑞看起来像这样...

//Segue for glasses one 
if ([[segue identifier] isEqualToString:@"imageChangeSegue"]) { 
    NewViewController *secondViewController = segue.destinationViewController; 
    secondViewController.theImageForTheImageView = [UIImage imageNamed:@"glasses_one.png"]; 
} 

故事板的图片:http://postimg.org/image/rcjfai52d/

我希望我已经解释得很好,如果没有,我已经上传了该项目供您查看。

下载Zip:https://mega.co.nz/#!9hxmjSZT!L7UFGpKBC5CsQQtuPGh0SVfRN4TdxLLRvh6jJW-TmD0

任何帮助将是非常赞赏。请注意,我是iOS开发新手,我从事Web开发工作,因此Objective-C和PHP编码之间的差异非常大。

非常感谢, 扎克。

+0

我认为您需要一个不同的范例来完成此项工作。当你选择一副眼镜,而不是延续到一个新的控制器时,它应该把你带回到带有你的照片的那个眼镜上,而且眼镜需要放在脸上的图像视图中,而且它需要可拖动,所以你可以将它移动到你想要的位置。眼镜图像也需要有一个他们目前没有的透明背景。 – rdelmar

回答

0

你的问题是你每次创建一个新的NewViewController。

//Segue for glasses one 
if ([[segue identifier] isEqualToString:@"imageChangeSegue"]) { 
    NewViewController *secondViewController = segue.destinationViewController; 
    secondViewController.theImageForTheImageView = [UIImage imageNamed:@"glasses_one.png"]; 
} 

你应该隐藏导航控制器,而不是,或保存在实际NewViewController显示的图片并进行设置也是新的。


在SidebarViewController.m中添加此方法以防止执行segue。

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 
{ 
    if ([identifier isEqualToString:@"imageChangeSegue"] || [identifier isEqualToString:@"glasses_two"]) { 
     return NO; 
    } 
    return YES; 
} 

更改处理程序是这样的:

//When glasses one button is pressed... 
- (IBAction)glass_one_pressed:(id)sender{ 
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    SWRevealViewController *contr = (SWRevealViewController *)appDelegate.initialViewController; 
    //close the sidebar 
    [contr revealToggleAnimated:YES]; 
    //set the new image 
    appDelegate.myNewViewController.glassView.image = [UIImage imageNamed:@"glasses_one.png"]; 
} 

在NewViewController补充:

- (void)viewDidAppear:(BOOL)animated 
{ 
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    appDelegate.myNewViewController = self; 
} 

在AppDelegate.h补充:

@property (strong, nonatomic) SWRevealViewController *initialViewController; 
@property (strong, nonatomic) NewViewController *myNewViewController; 

在AppDelegate中。m将此行添加到应用程序中:didFinishLaunchingWithOptions:方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    ... 
    //save the SWRevealViewController 
    self.initialViewController = (SWRevealViewController*)self.window.rootViewController; 

    return YES; 
} 
+0

嗨Daniele,谢谢你的帮助。我想知道是否可以给我一些示例代码或指导我到正确的地方学习如何隐藏导航控制器或将图片保存在NewViewController中以使其成为可能。我有一个小谷歌,尝试了不同的东西,但我还没有成功。再次感谢Zack。 –

+0

@ZackJones试试这个代码,它应该工作 – drolando

+0

你先生是一个天才!它完美的作品:)谢谢。 –

相关问题