Toggle Fullscreen action with Double Tap - ios

Looking for a way to implement a "full-screen" action reversible with double tap but I did not succeed!
More in detail, there are 2 UIView :
- topViewContainer
- bottomViewContainer
When I double-tap on the superview, the view "bottomViewContainer" extends to full-screen, and I re-double tap, the view returns to its original size.
It should work in portrait mode and Landscape Mode!
This is what I've done until now:
-(void)handleDoubleTap:(UITapGestureRecognizer *)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
if (sender.numberOfTapsRequired == 2){
NSLog(#"if gesture up - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, 480.0, 300.0);}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
} else if (sender.numberOfTapsRequired == 2) {
NSLog(#"else if gesture down - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 84.0, 480.0, 216.0);}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
if (sender.numberOfTapsRequired == 2) {
NSLog(#"if gesture down - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 640.0);
}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
else if (sender.numberOfTapsRequired == 2) {
NSLog(#"else if gesture up - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 244.0, self.view.frame.size.width, 216.0);
}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
}

Try this code :
#import "ViewController.h"
#interface ViewController (){
UIView *topContainerView;
UIView *bottomContainerView;
CGRect initialTopContainerView;
CGRect initialBottomContainerView;
BOOL isFullScreen;
}
#end
#implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
CGSize result = [[UIScreen mainScreen] bounds].size;
topContainerView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, result.width, result.height/2)];
topContainerView.backgroundColor = [UIColor redColor];
topContainerView.tag = 1;
[self.view addSubview:topContainerView];
bottomContainerView = [[UIView alloc]initWithFrame:CGRectMake(0.0, result.height/2, result.width, result.height/2)];
bottomContainerView.backgroundColor = [UIColor blueColor];
bottomContainerView.tag = 2;
[self.view addSubview:bottomContainerView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleDoubleTap:)];
tap.numberOfTapsRequired = 2;
[bottomContainerView addGestureRecognizer:tap];
UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleDoubleTap:)];
tap2.numberOfTapsRequired = 2;
[topContainerView addGestureRecognizer:tap2];
initialTopContainerView = bottomContainerView.frame;
initialBottomContainerView = topContainerView.frame;
isFullScreen = false;
}
return self;
}
-(void)handleDoubleTap:(UITapGestureRecognizer *)sender {
CGSize result = [[UIScreen mainScreen] bounds].size;
int heightSreen = result.height;
int widthSreen = result.width;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
heightSreen = result.width;
widthSreen = result.height;
}
if (sender.numberOfTapsRequired == 2) {
CGRect newFrameTop;
CGRect newFrameBottom;
isFullScreen = !isFullScreen;
if (isFullScreen) {
if (sender.view.tag == 1) {
newFrameTop = CGRectMake(0, 0, widthSreen, heightSreen);
newFrameBottom = CGRectMake(0, heightSreen, widthSreen, 0);
}else{
newFrameTop = CGRectMake(0, 0, widthSreen, 0);
newFrameBottom = CGRectMake(0, 0, widthSreen, heightSreen);
}
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = newFrameTop;
bottomContainerView.frame = newFrameBottom;
}completion:nil];
}else{
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, widthSreen, heightSreen/2);
bottomContainerView.frame = CGRectMake(0.0, heightSreen/2, widthSreen, heightSreen/2);
}completion:nil];
}
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

Related

How to get original image when we zoom in and zoom out the image in ios

Hi i am beginner in ios and in my project i am adding UIImage on UIScrollview and i have added tap gesture on UIImage
When we double click on UIImage then image should be zooming full screen size on view controller
After the full screen size image we can zoom it like any way what we want(i mean using like pinch zoom effect)here my requirement is when we double click on image then image need to set it's original position i have tried my level best but i did not get result please help me
my code is below:
#import "ViewController2.h"
#interface ViewController2 ()
{
UIScrollView * myScroll;
UITapGestureRecognizer *tap;
BOOL isFullScreen;
CGRect prevFrame;
UIImageView * _imageView;
}
#end
#implementation ViewController2
- (void)viewDidLoad
{
[super viewDidLoad];
isFullScreen = FALSE;
myScroll = [[UIScrollView alloc] init];
myScroll.frame = self.view.bounds;
myScroll.contentSize = CGSizeMake(_imageView.frame.size.width, _imageView.frame.size.height);
myScroll.maximumZoomScale = 4.0;
myScroll.minimumZoomScale = 1.0;
myScroll.clipsToBounds = YES;
myScroll.delegate = self;
myScroll.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:myScroll];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
[_imageView setClipsToBounds:YES];
_imageView.userInteractionEnabled = YES;
_imageView.image = [UIImage imageNamed:#"ram.jpeg"];
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imgToFullScreen:)];
tapper.numberOfTapsRequired = 1;
[_imageView addGestureRecognizer:tapper];
[myScroll addSubview:_imageView];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _imageView;
}
-(void)imgToFullScreen:(UITapGestureRecognizer*)sender {
if (!isFullScreen) {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
prevFrame = _imageView.frame;
[_imageView setFrame:[[UIScreen mainScreen] bounds]];
}completion:^(BOOL finished){
isFullScreen = TRUE;
}];
return;
}
else{
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
[_imageView setFrame:prevFrame];
}completion:^(BOOL finished){
isFullScreen = FALSE;
}];
return;
}
}
#end
I did some modifications in your code as like below try it .Check it give your wanted output or not.
#interface ScrollViewController ()<UIScrollViewDelegate>{
UIScrollView * myScroll;
UITapGestureRecognizer *tap;
BOOL isFullScreen;
CGRect prevFrame;
UIImageView * _imageView;
CGAffineTransform trans;
}
#end
#implementation ScrollViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
isFullScreen = FALSE;
myScroll = [[UIScrollView alloc] init];
myScroll.frame = [UIScreen mainScreen].bounds;
myScroll.contentSize = CGSizeMake(prevFrame.size.width, prevFrame.size.height);
myScroll.maximumZoomScale = 4.0;
myScroll.minimumZoomScale = 1.0;
myScroll.clipsToBounds = YES;
myScroll.delegate = self;
myScroll.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:myScroll];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
[_imageView setClipsToBounds:YES];
_imageView.userInteractionEnabled = YES;
_imageView.image = [UIImage imageNamed:#"img.png"];
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imgToFullScreen:)];
tapper.numberOfTapsRequired = 2;
[_imageView addGestureRecognizer:tapper];
[myScroll addSubview:_imageView];
prevFrame = _imageView.frame;
trans = _imageView.transform;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _imageView;
}
-(void)imgToFullScreen:(UITapGestureRecognizer*)sender {
if (!isFullScreen) {
myScroll.contentSize = prevFrame.size;
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
_imageView.frame = [UIScreen mainScreen].bounds;
}completion:^(BOOL finished){
isFullScreen = TRUE;
}];
return;
}
else{
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
myScroll.contentSize = CGSizeMake(prevFrame.size.width, prevFrame.size.height);
_imageView.transform = trans;
_imageView.frame = prevFrame;
NSLog(#"%# %#",NSStringFromCGSize(myScroll.contentSize),NSStringFromCGRect(prevFrame));
}completion:^(BOOL finished){
isFullScreen = FALSE;
}];
return;
}
}

Animation is not coming out correctly

I'm creating a menu that slides from the bottom and up via a UIButton that is pressed to activate the animation. But the animation is coming out incorrectly. It is supposed to work like this -https://youtu.be/79ZQDzzOHLk?t=2m52s (but in portrait mode) But here's how it works after I coded it:
And here's the codes for the animation in the viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];
openMenu.frame = CGRectMake(220, 270, 60, 30);
}
- (IBAction)OpenMenu:(id)sender {
if (draw1 ==0) {
draw1 = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 245, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
} else {
draw1 = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];
scrollView.frame = CGRectMake(0, 300, 568, 55);
openMenu.frame = CGRectMake(220, 270, 60, 30);
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
}
}
#end
How do I fix it so the UIButton comes at the bottom of the screen in portrait mode and it goes up and down like in the Youtube tutorial?
Change it to this:
#import "ViewController.h"
#define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)
#define SCREEN_HEIGHT ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width)
#interface ViewController ()
#end
#implementation ViewController
#synthesize scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
draw1 = 0;
scrollView.frame = CGRectMake(0, SCREEN_HEIGHT-55, SCREEN_WIDTH, 55);
[scrollView setContentSize:CGSizeMake(SCREEN_WIDTH, 55)];
[scrollView setContentSize:CGSizeMake(480, 55)];
}
- (IBAction)OpenMenu:(id)sender {
if (CGAffineTransformIsIdentity(scrollView.transform)) {
[UIView animateWithDuration:0.5 animations:^{
scrollView.transform = CGAffineTransformMakeTranslation(0, 55);
}];
} else {
[UIView animateWithDuration:0.5 animations:^{
scrollView.transform = CGAffineTransformIdentity;
}];
}
}
#end
or, just change this method from what is above to the following (it's the same thing, just more elegant and simpler):
- (IBAction)OpenMenu:(id)sender
to this:
- (IBAction)OpenMenu:(id)sender {
[UIView animateWithDuration:0.5 animations:^{
scrollView.transform = CGAffineTransformIsIdentity(scrollView.transform) ?
CGAffineTransformMakeTranslation(0, 100):CGAffineTransformIdentity;
}];
}

iOS Views return to original locations when textView becomesFirstResponder

Hello and thank you in advance...
I am moving views frame location in animation blocks. After I move views, I am tapping a textView to allow for editing/input. When the textView is tapped, the views I moved previously pop back to their original (unmoved) frame locations.
I'm not sure what I am doing incorrectly here.
THIS IS HOW I SETUP THE DIFFERENT FRAME POSITIONS TO ANIMATE TO
//Books active and rest position will effect other elements (paper and paperTextView)
self.bookRestPosition = CGRectMake((self.view.frame.size.width * 0.10), (self.view.frame.size.height * 0.4), self.view.frame.size.width, self.view.frame.size.height);
self.bookActivePosition = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +100, self.view.frame.size.width, self.view.frame.size.height);
self.bookOpenPosition = CGRectMake(self.bookActivePosition.origin.x, self.bookActivePosition.origin.y, 20, self.bookActivePosition.size.height);
self.quillRestPosition = self.quill.frame;
self.quillActivePosition = CGRectMake(self.quill.frame.origin.x, self.view.frame.origin.y -200, self.quill.frame.size.width, self.quill.frame.size.height);
self.woodTableRestPosition = self.view.frame;
self.woodTableActivePosition = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -200, self.view.frame.size.width, self.view.frame.size.height +200);
self.paperRestPosition = self.bookRestPosition;
self.paperActivePosition = CGRectMake(self.bookOpenPosition.size.width, self.bookActivePosition.origin.y, self.bookActivePosition.size.width, self.bookActivePosition.size.height);
self.paperTextViewRestPosition = self.bookRestPosition;
self.paperTextViewActivePosition = self.paperActivePosition;
self.paperTextView.editable = NO;
self.paper.alpha = 0.0;
self.paperTextView.alpha = 0.0;
self.paper.frame = self.bookRestPosition;
self.paperTextView.frame = self.bookRestPosition;
THIS IS HOW I ANIMATE THEM
- (IBAction)onBookTapped:(UITapGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == self.bookRestPosition.origin.x) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self activateLogAndViewsAssociated];
} completion:^(BOOL finished) {
NSLog(#"Book Slid up!");
}];
}
else if (self.logCover.frame.origin.x == 0){
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self everythingAtRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
}
- (IBAction)swipeBookLeft:(UISwipeGestureRecognizer *)sender {
//if (self.logCoverImage.frame.origin.x == 0) {
self.paper.alpha = 1.0;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookOpenPosition];
self.editButton.alpha = 1.0;
self.editButton.enabled = YES;
} completion:^(BOOL finished) {
NSLog(#"Book Has Opened!");
//This must be here. The paperTextView is what the swipe right gesture is attached to
self.paperTextView.alpha = 1.0;
// self.logCoverImage.alpha = 0.0;
// self.quill.alpha = 0.0;
}];
//}
}
- (IBAction)onPaperSwipeRight:(UISwipeGestureRecognizer *)sender {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookActivePosition];
self.editButton.alpha = 0.0;
self.editButton.enabled = NO;
} completion:^(BOOL finished) {
NSLog(#"Book Has Closed!");
//self.paper.alpha = 0.0;
// [NSUserDefaults *log = [NSUserDefaults standardUserDefaults];
// [log setObject:self.paperTextView forKey:#"textLog"];
}];
}
- (IBAction)onBookSwipeDown:(UISwipeGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == 0) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self everythingAtRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
}
- (IBAction)onBookSwipeUp:(UISwipeGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == self.bookRestPosition.origin.x) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self activateLogAndViewsAssociated];
} completion:^(BOOL finished) {
NSLog(#"Book Slid up!");
}];
}
}
- (void)animateAtStartup
{
self.logCover.frame = CGRectMake(self.view.frame.size.width, self.view.frame.size.height, self.bookRestPosition.size.width, self.bookRestPosition.size.height);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
AND THIS IS WHAT HAPPENS WHEN THE EDIT BUTTON IS PRESSED
- (IBAction)onEditButtonPressed:(id)sender
{
self.paperTextView.editable = YES;
[self.paperTextView becomeFirstResponder];
}

Override Double Tap to Zoom in MKMapView

Is it possible to replace this gesture in iOS 6 with a custom gesture? I have a gesture to show the map in full screen by hiding the status and navigation bars and it works but it also zooms every time it is done.
Here is how I currently have my gesture implemented.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
in viewDidLoad:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(toggleBars:)];
tap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tap];
tap.delegate = self;
gesture method:
- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
BOOL barsHidden = self.navigationController.navigationBar.hidden;
if (!barsHidden)
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self hideTabBar:self.tabBarController];
}
else if (barsHidden)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[self showTabBar:self.tabBarController];
}
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}
methods for hiding/showing the tab bar:
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
float fHeight = screenRect.size.height;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
view.backgroundColor = [UIColor blackColor];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height - 49.0;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width - 49.0;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
[UIView commitAnimations];
}

Re-initialize UIView view and subview after rotation

I have a little problem with size reset of my views after rotation and i can't fix it.
I put an "swipe" action on my view "bottomContainerView" and the size is different depending the orientation!
here is my new code:
-(void)swipeToggle:(UISwipeGestureRecognizer *)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
if (sender.direction == UISwipeGestureRecognizerDirectionUp){
NSLog(#"if gesture up - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, 480.0, 300.0);}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
} else if (sender.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(#"else if gesture down - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 84.0, 480.0, 216.0);}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
if (sender.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(#"if gesture down - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 640.0);
}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
else if (sender.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(#"else if gesture up - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 244.0, self.view.frame.size.width, 216.0);
}
completion:^(BOOL finished){
NSLog(#"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
}
POST UPDATED - Here is my new code correct with what you taught me and kindly explain ;-)
My eyes take damage when looking at this code.
Here you are trying to combine 2 ways of declaring animation.
If you are using beginAnimations: you don't have to use [UIView animateWithDuration:] method, but have to finish your animation code with [UIView commitAnimations];
The clearest way is to use [UIView animateWithDuration:] and put animation code inside animations:^{} block.
P.S: I strongly recommend not to use magic numbers in your code and use constants instead. SwitchToFullNormalScreen and SwitchToNormalScreen animations are just copypasted. I mean come on, that's not good.

Resources