I have a UIView with a UINavigation controller and several other Imageviews and a text filed inside it. On the Nagivation bar there is a UIBarbutton item which pushes another ViewController.
When the text field in the Navigation Viewcontroller is tapped it brings up the keyboard causing the Navigation bar with UIBarbutton item to slide out of the screen and thus making the UIBarbutton item unaccessible until the done button is pressed on the keyboard.
A notification is sent to this method whenever the keyboard is invoked.
- (void)displayKeyboard {
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0.0, -100.0);
}
I tried using the IB to add a scrollview onto the view but this causes the entire view to be blocked.
Is there any other way i can enable the scroll view whenever the keyboard appears so i can scoll the entire screen ?
maybe you could try setting the frame of the current view.. for example:
CGRect r = self.view.frame;
self.view.frame = CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height-100);
and when the user done with the keyboard, add 100 to bring it back.... (instead of 100, you should get the value from the notification object that contains the height, position of the keyboard)...
Related
how to add a UIView in place of keyboard when we click accessory button using JSQ message view controller in swift
i am using JSQ message library in my app so i want add a UIView in which there are stack view which i want to show on on the click of accessary button in swift.
I created the View on storyboard, on click of accessory button this view will show.
I don't understand where this view will append in chat screen.
override func didPressAccessoryButton(sender: UIButton!){
self.inputToolbar.contentView.addView(View)
}
that will produce the nil exception
That my view i want to appent on the keyboard when accessary button click
I would suggest just adding your "Custom View" to the main view and giving it constraints to be where the keyboard is normally not actually adding it to the keyboard view.
Use the below code to have such effect and add your desired subview instead of demoView:
[self.inputToolbar.contentView.textView resignFirstResponder];
UIView *demoView = [UIView new];
demoView.backgroundColor = [UIColor redColor];
In below line you can decide the frame you want:
demoView.frame = CGRectMake(0, 0, self.inputToolbar.contentView.width/2, self.inputToolbar.contentView.height);
[self.inputToolbar.contentView addSubview:demoView];
And if you want some other kind of view like below:
[self.inputToolbar.contentView.textView resignFirstResponder];
UIView *demoView = [UIView new];
demoView.backgroundColor = [UIColor redColor];
demoView.frame = CGRectMake(0, 0, self.view.width, 200);
[self.view addSubview:demoView];
I am trying to emulate the way TweetBot/NetBot animates the tabBar in after a push from the tableView of Accounts action. When the view is fully pushed, only then does the taBar animate in from the bottom. I have tried all sorts of hide/show methods and all seem to fail when it comes to the "show" part.
Does anyone have a suggestion as to how this can be done?
First of all, I presume you are not using a UITabViewController since it cannot be pushed into a UINavigationController stack, so I think you are using a standalone UITabBar embedded in a UIViewController. Is this assumption right?
Try with this code (I didn't try it).
- (void)viewDidAppear {
[super viewDidAppear];
// Calls showTabBar method after SOME_DELAY. You can also call directly [self showTabBar] if you want zero delay.
[self performSelector:#selector(showTabBar) afterDelay:SOME_DELAY];
}
- (void)showTabBar {
// Before the animation begins, your UITabBar must be outside the view controller's view frame.
CGRect tabBarFrame = CGRectMake(0,
CGRectGetHeight(self.view.bounds),
CGRectGetWidth(self.view.bounds),
CGRectGetHeight(self.tabBar.frame);
self.tabBar.frame = tabBarFrame;
// Let's start with the animation, setting a new frame for tab bar inside an animation block
[UIView animateWithDuration:ANIMATION_DURATION animations:^{
// Change origin Y. It assumes that the height of self.tabBar is right, otherwise put the height you want instead of CGRectGetHeight(self.tabBar.frame).
tabBarFrame.origin.y = CGRectGetHeight(self.view.bounds) - CGRectGetHeight(self.tabBar.frame);
self.tabBar.frame = tabBarFrame;
}];
}
So I am using WEPopover to display a custom view controller pop up. I have a UIView in which inside it has another UIView called containerView. Inside this containerView, I have a UIButton. This is where I wanted to present my popover from. So here's what I did:
[self.popoverDialog presentPopoverFromRect:sender.frame inView:self.containerView permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
The issue is that the arrow and everything is showing from this button, but the popover goes out of self.containerView bounds. How can I make it so that the popover is displayed within the containerView bounds?
EDIT:
A picture is worth a thousand words, so here it is:
The light gray is the containerView I mentioned above. THe popover theoretically should be shown within that light gray bounds not going outside.
For the view that is contained inside the popover, go to it's view controller and set it's property contentSizeForViewInPopover. Here you can set the size so that it fits the bounds of your containerView.
OP wants to position the popover so that it only shows up in his container view. I found this bit of code in the WEPopoverController.m file
- (void)repositionPopoverFromRect:(CGRect)rect
inView:(UIView *)theView
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections {
CGRect displayArea = [self displayAreaForView:theView];
WEPopoverContainerView *containerView = (WEPopoverContainerView *)self.view;
[containerView updatePositionWithAnchorRect:rect
displayArea:displayArea
permittedArrowDirections:arrowDirections];
popoverArrowDirection = containerView.arrowDirection;
containerView.frame = [theView convertRect:containerView.frame toView:backgroundView];
}
You could possibly call this method and it might reposition your popover so that it is now inside your container viw.
I have a UITextfield in a tableview in a view controller, and I am displaying this view in a UIPopOverView. I wanted to know how can I get to know the position of the textfield with respect to IPAD screen...so that i can move my tableview upwards on Textfield editingDidBegan
Try using the convertPoint:toView: or convertRect:toView: methods of UIView.
So for example, to get the textField's bounds relative to the window, say
CGRect *bounds = [textField convertRect:textField.bounds toView:window];
I have an iPhone application that's using Navigation Controller to display the top bar (with title and back button, and such...).
I added a UITabBar to the application window, that enables to switch between the parts of it. Instead of adding the tab bar to each of ViewController's view I added the bar to app window.
(When I had it in the ViewController, switching between controllers made the tab bar to swipe left/right, when animated pop/push occured, together with whole view).
So, I added the UITabBar to the MainWindow.xib, and tied it to the app delegate's variable. In my didFinishLaunchingWithOptions method, I added the following code:
[self.window addSubview:navigationController.view];
CGRect frame = navigationController.view.frame;
frame.size.height -= tabbar.frame.size.height;
navigationController.view.frame = frame;
tabbar.selectedItem = [tabbar.items objectAtIndex:0];
to resize the main (navigationController's) view, in order to make the TabBar visible.
The problem shows up when I rotate the device -- my view gets stretched to full window and I loose the ability to show the TabBar.
I added a - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation method to my ViewController, with the following code:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGRect frame = self.view.frame;
frame.size.height -= [AppState shared].tabBar.frame.size.height;
//frame.origin.y = [AppState shared].tabBar.frame.size.height;
//frame.origin.x = 100;
self.view.frame = frame;
frame = [AppState shared].tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.origin.y - frame.size.height;
[AppState shared].tabBar.frame = frame;
}
It resizes the view, and moves the tab bar to up/down part of the view (I allow only Portrait/Portrait upside down orientations here). The problem is, my TabBar is turned upside down as well, and also, it's no longer clickable.
It looks like the image below:
Anyone knows how to handle this kind of situation? Or, how to make the tab bar not tied to view controller, but also able to handle interface's rotation smoothly?
You are using the tabbar in an unintended way. You seem to be using the UITabBarView as an uncontrolled element of other views. That is not it's function.
The UITabBarView should be controlled directly by a UITabBarController which in turn should be controlling all the view controllers for the views displayed in the tabbar i.e. the tabbar controller is a type of navigation controller that controls subcontrollers.
Suppose you have three tabs and the third one is a navigation controller. Your controller hierarchy would look like this:
TabbarController:
-->tab1ViewController
-->tab2ViewController
-->tab3ViewController(UINavigationController):
-->rootViewController-->secondViewController
You are trying to move and manage the tabbar view without its controller and the proper controller hierarchy. That isn't going to work.