I have found a solution here How to flip an individual UIView (without flipping the parent view)
but it seems that this doesn't work for me. In Interface Builder i have set up all with a uiview and inside that two uiviews, with the same size and the first view to be shown on top and i have created three outlets for this 3 views.
In viewDidLoad:
[self.view addSubview:self.contentView]
[self.contentView addSubview:firstView]
[self.contentView addSubview:secondView]
i have a uigesture. When the user taps the screen, the IBAction executes the flip:
-(IBAction)flip:(id *)sender
{
if(faceUp){
// execute transition from firstview to second
}else{
//execute transition from secondview to first
}
faceUp = !faceUp;
}
this work perfectly the first time i click and the flips happens from the first to second, then if i tap again the flip starts and then it ends with nothing, the view disappears and remains the container view showing nothing because its color is set to clear. How can i resolve this?
This is the controller with the tap gesture method and the three outlets:
#import "ContactViewController.h"
#import "InfoContactView.h"
#import "ImageLogoView.h"
@interface ContactViewController ()
@property (strong, nonatomic) IBOutlet InfoContactView *contactInfoView;
@property (strong, nonatomic) IBOutlet ImageLogoView *imageLogoView;
@property (nonatomic) BOOL faceUp;
@property (strong, nonatomic) IBOutlet UIView *parentView;
@end
@implementation ContactViewController
- (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.
self.parentView.backgroundColor =[UIColor clearColor];
[self.view addSubview:self.parentView];
[self.parentView addSubview:self.contactInfoView];
[self.parentView addSubview:self.imageLogoView];
self.faceUp = NO;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setFaceUp:(BOOL)faceUp
{
_faceUp = faceUp;
}
-(void)setParentView:(UIView *)parentView
{
_parentView =parentView;
}
-(void)setContactInfoView:(InfoContactView *)contactInfoView
{
_contactInfoView = contactInfoView;
}
-(void)setImageLogoView:(ImageLogoView *)imageLogoView
{
_imageLogoView = imageLogoView;
}
- (IBAction)showInfo:(UITapGestureRecognizer *)sender {
if (self.faceUp == NO) {
[UIView transitionFromView:self.imageLogoView toView:self.contactInfoView
duration:1.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:NULL];
NSLog(@"Pass from logo to info : imageLogoView = %@",self.imageLogoView.description);
NSLog(@"dettagli = %@",self.contactInfoView);
}
else if(self.faceUp == YES){
[UIView transitionFromView:self.contactInfoView toView:self.imageLogoView
duration:1.5
options:UIViewAnimationOptionTransitionFlipFromRight
completion:NULL];
NSLog(@"Pass from info to logo: imageLogoView = %@",self.imageLogoView.description);
NSLog(@"dettagli = %@",self.contactInfoView);
}
self.faceUp = !self.faceUp;
}
@end