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];
}
Related
I've a problem with date picker. When I touch on textfield(datumletu) I call picker and datumletu [resign firstresponder]. But no effect.
Here is my code. I'm trying everything but nothing is working.
-(void)textFieldDidBeginEditing:(UITextField *)textField {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if (textField == self.datumLetu) {
[self.view endEditing:YES];
[self.autoTextFieldPriletu resignFirstResponder];
[self.autoTextField resignFirstResponder];
[self.cisloLetu resignFirstResponder];
[self.datumLetu resignFirstResponder];
self.picker.hidden = YES;
[self showPicker];
CGRect rect = self.view.frame;
if(rect.origin.y == 0)
{
rect.origin.y -= 110;
rect.size.height += 110;
[UIView animateWithDuration:0.2 animations:^{
self.view.frame = rect;
}];
self.picker.frame = CGRectMake(0, screenHeight / 2 + screenHeight / 3.2, screenWidth, screenHeight/2);
}
and picker
-(void)showPicker
{
[self showAction];
}
-(void) showAction
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
self.picker = [[Picker alloc] initWithFrame:CGRectMake(0, screenHeight / 2 + screenHeight / 10.5, screenWidth, screenHeight/2)];
[self.picker addTargetForDoneButton:self action:#selector(cancelPressed)];
[self.picker addTargetForCancelButton:self action:#selector(cancelPressed)];
[self.picker setMode:UIDatePickerModeDateAndTime];
[self.picker.picker addTarget:self action:#selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.picker];
self.picker.hidden = NO;
}
Any help is highly appreciated.
In your ViewController add the delegate of the UITextField :
#interface ViewController : UIViewController <UITextFieldDelegate>
While Creating the UITextField or in ViewDidLoad:
self.myTextField.delegate = self;
In your implementation file:
#pragma mark - UITextFieldDelegate
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField resignFirstResponder];
// show your picker here
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
I hope this question makes sense, I have a login screen, when I click on the one of my input fields (either Username or Password) a keyboard appears. but when that happens Everything moves in motion from left to right, so I have a big white space on the left side. What I am expecting is for everything to move from down to up instead. I really hope this makes sense. Here is my code:
- (void)animateTextField:(UITextField *) textField up: (BOOL) up;
- (void)NavButtonPressed: (UIButton*)sender;
- (void)NavButtonPressed: (UIButton*)sender
{
if([sender isEqual:navBarNextButton])
{
[self.idTextField resignFirstResponder];
[self.passwordTextField becomeFirstResponder];
currentResponder = 1;
[self animateTextField:self.passwordTextField up:NO];
[self animateTextField:self.passwordTextField up:YES];
[navBarNextButton setEnabled:NO];
[navBarPrevButton setEnabled:YES];
}
else
{
[self.passwordTextField resignFirstResponder];
[self.idTextField becomeFirstResponder];
currentResponder = 0;
[self animateTextField:self.idTextField up:NO];
[self animateTextField:self.idTextField up:YES];
[navBarNextButton setEnabled:YES];
[navBarPrevButton setEnabled:NO];
}
}
- (void)animateTextField:(UITextField *) textField up: (BOOL) up
{
int movementDistance;
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
if([textField isEqual:self.idTextField])
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-31.5f, 1024.0f, 45.0f)];
movementDistance = 110;
}
else
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-26.5f, 1024.0f, 45.0f)];
movementDistance = 115;
}
}
else
{movementDistance = 0;}
const float movementDuration = 0.3f;
int movement=0;
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft)
movement = (up? -movementDistance : movementDistance);
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
movement = (up? movementDistance : -movementDistance);
[UIView beginAnimations:#"keyboardtransition" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:movementDuration];
self.view.frame = CGRectOffset(self.view.frame, movement, 0);
[UIView commitAnimations];
}
If anyone could help, that would be amazing. My project Device is set to Landscape Right only.
I had same issue before, in iOS 7 and 8 it works differently. So I implemented a method for handling the issue:
- (void)keyboardHideShow:(UIView *)view shiftBy:(float)shiftAmount forState:(BOOL)state
{
float keyBoardOffset = shiftAmount;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect rect = [[[UIApplication sharedApplication] keyWindow] bounds];
if (state)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
{
if (orientation == UIInterfaceOrientationLandscapeLeft)
{
rect.origin.x -= keyBoardOffset;
}
else
{
rect.origin.x += keyBoardOffset;
}
}
else
{
rect.origin.y -= keyBoardOffset;
}
}
view.frame = rect;
[UIView commitAnimations];
}
You can call it like:
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:true]; // For up
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:false]; // For down
I'm new in ios Development. I have some question.
Now, in my project i have UITabBarController1 with 2 viewControllers(ViewController1, ViewController2).
ViewController1 is start Page.
When I run Every Page(ViewController1, ViewController2, ViewController3, ...) have UITabBarController.
But in some page(Example : ViewController4) i want to hide and add New UITabBarController2
in ViewController4
if I use command "hideButtomBar" in ViewController4 : UITabBarController is not appear.
if I don't use command "hideButtomBar" in ViewController4 : UITabBarController1 and UITabBarController2 is appear(both)
how to fixed it
thank for help and sorry for my mistake about english. ^^
Try using this to hide tabbar
- (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];
}
and
[self hideTabBar: UITabBarController1];
app.tabBarController.tabBar.hidden=TRUE;
app.tabBarController.tabBar.hidden=TRUE;
//Set some tab
[app.tabBarController setSelectedIndex:0];
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
I can successfully run tests on the iOS simulator using webdriver, the only concern that I have is that there is a bar at the bottom of the screen which prevents the whole screen from displaying. It is not causing tests to fail, just wondering if there is a way to remove/collapse it so that the whole screen displays.
If you are using Uitabbar then you can use:
[self hideTabBar:your tabbarcontroller];//call to hide the tabbar;
[self showTabBar:your tabbarcontroller];//call to show the tabbar;
- (void)hideTabBar:(UITabBarController *) myTabbarController
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *myView in myTabbarController.view.subviews)
{
if([myView isKindOfClass:[UITabBar class]])
{
[myView setFrame:CGRectMake(myView.frame.origin.x, 480,
myView.frame.size.width,
myView.frame.size.height)];
}
else
{
[myView setFrame:CGRectMake(myView.frame.origin.x,
myView.frame.origin.y,
myView.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
[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, 431, view.frame.size.width,
view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,
view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}