iOS Keyboard Making View Disappear - ios

I am having a bit of an issue here. I have my main view for my application, for different windows. I have put them off the view sight and they're animated to move into view when they are required, I have never had an issue with this before until I decided to create a text field. When I click the button to bring the view into show it appears, but when I click the text field to type and the keyboard loads the view disappears, but if I click the button to bring the view back the text field will be entered and ready to type. Anyone got any solutions? I am attaching the code below of the way the view is appearing.
Thanks,
CurtisB
- (IBAction)login:(id)sender {
sidebutton = #"0";
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.0];
[self.blackhide setFrame:CGRectMake(self.blackhide.frame.origin.x -750, self.blackhide.frame.origin.y, self.blackhide.frame.size.width, self.blackhide.frame.size.height)];
[UIView setAnimationDuration:0.5];
[self.button2 setFrame:CGRectMake(self.button2.frame.origin.x - 300, self.button2.frame.origin.y, self.button2.frame.size.width, self.button2.frame.size.height)];
[self.mainview setFrame:CGRectMake(self.mainview.frame.origin.x - 300, self.mainview.frame.origin.y, self.mainview.frame.size.width, self.mainview.frame.size.height)];
[self.sidebarview setFrame:CGRectMake(self.sidebarview.frame.origin.x - 376, self.sidebarview.frame.origin.y, self.sidebarview.frame.size.width, self.sidebarview.frame.size.height)];
[UIView setAnimationDuration:0.0];
[self.loginview setFrame:CGRectMake(self.loginview.frame.origin.x + 376, self.loginview.frame.origin.y, self.loginview.frame.size.width, self.loginview.frame.size.height)];
}

Try to bring the subview you want at the top to front by using following code:
[parentView bringSubviewToFront:childView];
For example, if you want to show VIEW_A, do that code whenever you are un-hiding that view. If still you get that issue, put that code when keyboard appears i.e. in UITextfield delegate method..
Add comment if you are still stuck..

Related

UIView animateWithDuration... not working in iOS 8

I have a problem with [UIView animationWithDuration] when trying to animate a button when the keyboard come up. I have a notification tell me when the keyboard comes up then I have the ViewController call this method in the view. The button animates but not correctly. It just animates from a random position on the screen to the position it was at previously. The reason I bring this up again is because I've seen answers from other posts saying that setting the view's translatesAutoresizingMaskIntoConstraints property to YES in the ViewController will fix the problem, but it doesn't fix the problem.
[self.view setTranslatesAutoresizingMaskIntoConstraints:YES];
The animation is below:
- (void)animateForKeyboardAppearanceWithKeyboardSize:(CGSize)keyboardSize; {
[UIView animateWithDuration:0.3f
animations:^{
[self.sendSMSButton setFrame:CGRectMake(0,
self.frame.size.height - keyboardSize.height - self.sendSMSButton.frame.size.height,
self.frame.size.width,
self.sendSMSButton.frame.size.height)];
}];
}
Anyone know what's happening? Thanks in advance.
Have you ensured that this method isn't being called repeatedly? Also try subclassing the button, override -setFrame and double check to see if something else is setting the frame of your button while you are trying to animate it.

MFMailComposeViewController Resets Other View Frames

When you click a "contact" button in my app, a number of views are animated to slide the initial views out and the contact views in. One of the options at that point is to send and email. When you tap that button, I use MFMailComposeViewController to show the in-app email view.
The Issue:
As the email view animates in, the display reverts back to almost the initial view. The views in which I animated their frame, are reset to their original locations, but the one view I fade out stays faded out.
I am fairly certain I am not doing anything out of the ordinary with the animations and the mail composer code is exactly the same as all the references I have found.
EDIT:
Here is my animation code. I am basically animate a couple views off the screen and a couple others on the screen. Everything is layed out in a single view controller on a storyboard.
[UIView animateWithDuration:0.5f animations:^{
searchView.frame = CGRectMake(0, originalSearchY - searchView.frame.size.height, searchView.frame.size.width, searchView.frame.size.height);
footerView.frame = CGRectMake(0, originalFooterY + footerView.frame.size.height, footerView.frame.size.width, footerView.frame.size.height);
refreshView.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5f animations:^{
supportView.frame = CGRectMake(0, 64, supportView.frame.size.width, supportView.frame.size.height);
closeView.frame = CGRectMake(0, originalCloseY - closeView.frame.size.height, closeView.frame.size.width, closeView.frame.size.height);
} completion:^(BOOL finished) {}];
}];
Here is a screen flow of whats happening for clarification...
Tap the contact button, animated to the contact screen
Tap on the email button, email composer is shown
Cancel or send email
As you can see the visibility is reverted back to screen 1, with "update data" view gone (this is the view I fade out rather than animate the frame)
Ok, so I finally figured out the issue. I was doing some initialization in - (void)viewDidLayoutSubviews and that is called as the modal email view appears and as it is dismissed. I ended up adding a boolean "isInitialized" variable and tweaking the view processing based on that.

hide/unhide UIPicker with the same animation

im currently making a project where i need to hide my UIPicker, i've done all the hiding and animation stuff with this code,
on button press event this code is written:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.8];
CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, -200);
self.picker.transform = transfrom;
self.picker.alpha = self.picker.alpha * (-1) + 1;
[UIView commitAnimations];
and on view did load initialized;
self.picker.alpha = 0;
[self.view addSubview:self.picker]; //i dont really need this one
so here the picker will appear from button to top (0,-200) but when i click the button again it dissapears right away as self.picker.alpha goes to 0. i tried also putting animation delay and [UIView setAnimationDelay:3]; and tried also to set the animationDuration more but it does not effect when its going to hide.
i would like to know if how do i make the UIPicker hide in the same manner as it appears.
hope its not so confusing.
thanx
To reset the view to its original position you would want to reset the transform to CGAffineTransformIdentity.
As #Wain mentioned, you have changed the transform property while appearing the UIPickerView.
When you want to disappear the Picker View on click of a button you need to set its transform again.
Here is a link to learn animation in UIView in iOS:
http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

How to hide custom tab bar button when hidesBottomBarWhenPushed is "TRUE"

I am using the code snippet from Tito to add a custom button to my tab bar:
https://github.com/tciuro/CustomTabBar
(Subclassing UITabbarController and adding a custom button using
// .. created a UIButton *button
[self.view addSubview:button];
)
This works great with my storyboard-based app except for the case of a subview within a navigation controller with the option "Hides bottom bar on push" enabled.
This hides the tab bar as promised, but not the custom button.
Seems like the button should be added as a subview to the tab bar itself?
I tried this ugly code which did not even make the button show up:
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view addSubview:button];
break;
}
}
Any ideas?
UPDATE:
My solution:
In my ApplicationDelegate i define the following methods, which i call whenever needed in the viewWillAppear or viewWillDisappear methods:
-(void)hideCenterButton:(BOOL)animated
{
if(animated){
[UIView animateWithDuration:0.3
delay:0.0f
options:UIViewAnimationCurveLinear
animations:^{
CGRect frame = self.centerButton.frame;
frame.origin.x = -100;
self.centerButton.frame = frame;
}
completion:^(BOOL finished){
}];
}
}
-(void)showCenterButton:(BOOL)animated
{
if(animated){
[UIView animateWithDuration:0.35
delay:0.0f
options:UIViewAnimationCurveLinear
animations:^{
CGRect frame = self.centerButton.frame;
frame.origin.x = (self.view.superview.frame.size.width / 2) - (self.centerButton.frame.size.width / 2);
self.centerButton.frame = frame;
}
completion:^(BOOL finished){
}];
}
}
I had to set the animation's duration to 0.35s to get a smooth effect in harmony with the tab bar.
Why don't you make button your tabbar's part.
tabBarController.tabBar.addSubView(yourButton)
everything would be solve. cheers!
One easy way to handle this would be to create an instance of the button in .h of your file.
UIButton *customTabButton;
When calling the hides bottom bar on push set the button property to hidden and reset it again in the other views if the bottom bar is visible.
shareFbButton.hidden=YES;
You can check this is the viewDidLoad of all the files and put this line of code if needed to make sure you are displaying the button and hiding the button on all the pages you need.
if(self.tabBarController.tabBar.isHidden){
// set or reset the custom button visibility here
}
This is one way.
I think there are 2 ways you can got with this.
1) try to get the button into a view that is above the old top view controller and the tab bar BUT below the new top view controller that is pushed.
2) animate away the button when the new view controller is pushed.
The first will require mucking with the iOS proprietary view hierarchy which is undocumented, unsupported and could change anytime.
The second will be a matter of making the animation appear smooth enough for your user not to notice. It's not entirely a matter of behaving perfect, just appearing appropriately.
I would personally recommend an animation of the the button disappearing (animate it's alpha to 0) and reappearing based on if your view controller that goes over the tab bar is appearing or disappearing.
The animation for a navigation is (I believe) 0.3 seconds. If the button is in the middle of the tab bar, you'll likely want it invisible as the animating in view controller reaches it (if not sooner) so something between 0.1 and 0.15 seconds could be used to animate it out.
Now this does not make the button behave exactly the same as the tab bar, but with the quickness of the transition being so short, it will be unnoticeable really to the user.
Now just to provide a question for you to ask yourself. Why do you need to push a view controller that overlaps the tab bar? Why is that more desirable/necessary than presenting a modal view controller? If you can strongly argue for it, keep at it and good luck, if it's not necessary however, you may be able to achieve the experience you want with a modal view controller.
Check this one to put a button on the UITabBar. See if it works after with hidesBottoBarWhenPushed.

How to present datepicker only upon click of a button

I need to know if a date picker can be presented like an alert view upon the click of a button. So far, I have hidden the date picker in viewdidload method and set hidden=no in the method for the button.
I intend to store the date within Core Data.
Create the pickerView, place it outside of your view bounds, add it as a subview and use animation to slide it up. Something like the below should work...
CGRect frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 215);
UIPickerView *typePicker = [[UIPickerView alloc] initWithFrame:frame];
[self.view addSubview:typePicker];
[UIView beginAnimations:#"slideIn" context:nil];
[typePicker setCenter:CGPointMake(typePicker.center.x, self.view.frame.size.height - typePicker.frame.size.height/2)];
[UIView commitAnimations];
You put the date picker in a subview and then present the subview at the click of a button. You probably want the subview to slide in from the side or bottom.

Resources