Push view controller after setting view - ios

Suppose i have a uiview in 1 screen and i want to view the same view in fullscreen mode on click of a button.
On click of a button the following function is called.
-(IBAction)fullScreen
{
FullScreenViewController *mv = [[FullScreenViewController alloc] init];
mv.fullview = minimizedView;
//minimizedView is a UIView already created with a specified frame
// fullview is a UIView decalred in FullScreenViewController
[[self navigationController] pushViewController:mv animated:YES];
}
In the FullScreenViewController.m the viewDidLoad function is as follows :
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:fullview];
}
On click of the fullscreen button, the view appears but on click of back button, the minimized view in the previous page dissapears.
Is it wrong to do this?

You dont need to use two views to implement this. In your code, your are navigating from one view to another view. You dont need to do that. Your minimizeView itself having a property "setFrame:" to increase and decrease its frame to resize of that subview in your current view itself. Learn how to resize the UIView.

Related

UITableView inside childviewcontroller not receiving all taps

I've got a UITableview that displays the search results of a UISearchController. They are inside of a Childviewcontroller.
I write the text on the textfield of the parentviewcontroller and it passes the text to the searchbar of the child view controller.
This all works fine.
But for some reason, when I am choosing a result in the child view controller's tableview, it is not very responsive.
After typing in the search text in the textfield (having the textfield as the firstResponder), most of the times I have to tap more than once to select a row.
(P.S. userInteraction is enabled, otherwise no touch would ever go through.)
Any idea why?
I have same problem, and my solution is:
- (void) displayContentController: (UIViewController*) content{
[content.view setFrame:recorderView.bounds];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:content];
childNavController.toolbarHidden = NO; // if you show toolbar
childNavController.view.frame = content.view.frame;
[self addChildViewController:childNavController];
[recorderView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
}
content is my subViewController
Is this for Swift or for Objective-C? Also are you placing a UI Tap Gesture Recognizer on the views that you wish to be touchable?

InputAccessoryView covers the bottom bar

Any idea how to get an inputAccessoryView to anchor to the tab bar rather than the bottom of the screen?
I have created a UIViewController and overridden the following methods:
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(UIView *)inputAccessoryView {
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
self.keyboardInputAccessoryView =[[BRKeyboardInputBarView alloc] initWithFrame:frame leftButtonTitle:#"Left" andRightButtonTitle:#"Send"];
[self.keyboardInputAccessoryView setDelegate:self];
[self.keyboardInputAccessoryView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.keyboardInputAccessoryView removeFromSuperview];
return self.keyboardInputAccessoryView;
}
View controller with inputAccessoryView covering the tab bar
By the looks of it the view controller adds the view to the window rather than the current view controllers view, which would explain its positioning. However if I remove the line:
[self.keyboardInputAccessoryView removeFromSuperview];
I get a crash when I tap in the textview of my accessory view:
The view hierarchy is not prepared for the constraint:<NSLayoutConstraint:0x7fa0c2ca5f80 BRKeyboardInputBarView:0x7fa0c2d6fad0.bottom == UIInputSetContainerView:0x7fa0c295a2c0.bottom>
So I guess what I am asking is what is the correct way to add a keyboard accessory view so that it plays nicely with auto layout and avoids the crash, but also anchors itself to the view and not the window?
What you are seeing is the right behaviour.
The results you are seeing is because of the fact that UIViewController is a UIResponder subclass. By overriding the inputAccessoryView and returning an instance of a view, UIViewController will take care of placing that view at the bottom of the screen and animating it appropriately when keyboard appears or disappears.
If you want to add this bar on top of your keyboard, then you need to set the property inputAccessoryView of a textField/textView to your custom view.

how to show an overlapping view iOS

I have a view with some UI components and a button on it, upon touch of a button I want to show a half view with some textfields on it overlapping the initial view, the initial view should be visible partly , the overlapping view will cover only half screen from bottom. Is this possible ?
I don't have any code as I am unable to figure out what it needs to be done, as we show any view it covers the entire screen.
Thanks
there are several ways you can do this, here are two:
1) add a popover controller that gets displayed on your button press:
here's some apple documentation on popovers: https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/Popovers.html
2) add the new view as a subview to your UIViewController
PROGRAMICALLY:
in the viewDidLoad function you can do the following to initialize the halfScreenView
GLfloat topOffset = self.view.frame.size.height/2;
UIView halfScreenView = [[UIView alloc] initWithFrame: CGRectMake(0, topOffset , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - topOffset)
[self.view addSubview:halfScreenView];
-more logic might be needed if you support Landscape orientation, you can always re-assign the location of the view with halfScreenView.frame.origin and halfScreenView.frame.size
-initially you can have this view be hidden
halfScreenView.hidden = YES;
-when you click the button it will show the overlaying view:
halfScreenView.hidden = NO;
USING STORYBOARD:
you can also set up your overlaying view in the storyboard if you have one
-drag a UIView into your UIViewController and set it up where you want it to be located
-initialize the view to be hidden by checking the hidden box in the attribute inspector
-add the view as a property to your view
-manage when to show this view with self.halfScreenView.hidden
-this technique allows you to customize what is inside the new view within the storyboard which is nice
FOR BOTH:
-be careful with layers, you don't want your view to show up behind the one you already present. In the storyboard the last thing inserted goes on top. With in the code you can always access/change the views z position with halfScreenView.layer.zPosition (higher z values are on top)
First create a new class subclassing UIViewController called SecondView (or whatever you want), then design the UI the way you want (in its .xib file)
Then go to your main view controller's file and make an IBAction for that button.
In that method, write:
SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height/2, height, width);
[self.view addSubview:second.view];
This will add it to the bottom half of the screen. Put your own parameters for its height and width. When you want to dismiss the view, you can do this inside your SecondView class
[self.view removeFromSuperview];
You can deal with the textFields from within the SecondView class and have them communicate with your other view by doing the following in SecondView.h
#property IBOutlet UITextField* textField;
Hope this helps!
Yes, assuming you are using Interface Builder, go ahead and build the overlapping view and hook up all of the IBOutlets and IBActions. Say this view is called myView. Set myView.hidden = YES and myView.enabled = NO. This hides and disables myView so that it isn't even there from the user's perspective. In the appropriate button's IBAction, change the hidden and enabled properties to YES. That will make the view visible and active again.

iOS: WEPopoverController in MKMapView

Because i have more than one element to display at a given location in a mapview, i'd like to display a WEPopoverController in the MKMapView when a given MKPinAnnotationView has been selected.
Presenting the content, which is a tableview works fine so far. I've subclassed the MKPinAnnotationView and when the annotation view gets clicked, i call my custom presentation method.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
[view openCustomPopoverInFrame:self.view.frame];
[mapView deselectAnnotation:view.annotation animated:NO];
if (_lastAnnotationView != view) {
[_lastAnnotationView closeCustomPopover];
_lastAnnotationView = view;
}
}
- (void) openCustomPopoverInFrame:(CGRect) frame {
CGRect fromFrame = self.frame; //Pin Annotation View Frame
WEPopoverContentViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
contentViewController.delegate = self;
WEPopoverController *viewController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
//[viewController setPassthroughViews:[NSArray arrayWithObjects:contentViewController.view, contentViewController.tableView, nil]];
viewController.delegate = self;
//set the displayed content
....
_myPopoverController = [viewController retain];
[viewController presentPopoverFromRect:fromFrame inView:self.superview permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown animated:YES];
[contentViewController release];
[viewController release];
}
Also selecting buttons in the tableview cells work find and i get the expected response (the method gets called and the popovercontroller stays on top of the view hierarchy).
My problem is, when i click on the WEPopoverController Content (one of the table view cell, in the center, where no button is located), the tap event gets passed through to the map view and therefore hides the popover controller. What can i do, to prevent passed through tap events?
I tried several solutions e.g. set the passThroughViews and also manipulating the hitTest:withEvent: method in the WETouchableView and always return nil, but that also doesn't help me any further.
Best
Nic
EDIT
I've now debugged the hitTest:withEvent: method in the WETouchableView a little more in dept and it seems, that it always returns an instance of UITableViewCellContentView, which i think should be correct so far.
EDIT
So to be a little bit more clear, i want to display a popover controller and when it gets tapped it should neighter disappear like it is the usual annotation behavior nor the underlying view should get called. It should stay on top of the view and the tap event should get caught by the table view and call the specific method (tableView:didSelectRowAtIndexpath:).
I've looked at this solution aswell, but it seems not to work for me and the underlying view (wich is the map view) gets called.
Ok, what worked for me, was to add a UIButton with a transparent background color as the first subview of the table view cell. All Tap Events on the cell now get caught by the UIButton. Btw all swipe events get caught by the table view, so at least that works fine.
To be honest, this isn't a really nice solution, but it works for me. I'd really appreciate any further suggestions!
Best
Nic

Add a button to float on top of a ViewController, Path inspired

I am trying to build a button that will be floating on top of a ViewController, it should remain in the same position statically while the viewcontroller beneath it can scroll up and down.
I designed my own button class and in the viewdidload of the parent Viewcontroller I am doing this :
- (void)viewDidLoad// this is the parent viewcontroller
{
[super viewDidLoad];
customButton *floatingButton = [[UIButton alloc]initWithFrame:(self.view.frame)];
[floatingButton setLocation:CGPointMake(300, 430)];
[self.view addSubview:floatingButton];
[self.view bringSubviewToFront:floatingButton];
This is not doing it, as in when I run the button doesn't show up, only the view controller.
How can I achieve this?
I don't think that you're initializing your button properly. initWithFrame is a UIView initializer, being called by a regular UIButton. I don't see how you would get anything but an empty view here.
If you have a custom initializer for your custom button you should use
[[CustomButton alloc] myCustomInitializerWithFrame:frame];
Thanks guys, but the error was on my end, I wasn't initializing the frame properly, so the button was there but had a height and width of (0,0).

Resources