Change height of formSheet in iOS 8 - ios8

I just have one question related to presenting a from sheet view controller in iOS 8. In iOS 7 I was able to change the height of the view controller using the last line of code in the function below:
SendRemainingEvaluationsViewController *sendRemainingEvaluationViewController = [[[SendRemainingEvaluationsViewController alloc] initWithNibName:#"SendRemainingEvaluationsViewController" bundle:nil]autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sendRemainingEvaluationViewController] autorelease];
navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
//To Change the default size of the viewController which is presented in UIModalPresentationFormSheet presentation style
navigationController.view.superview.frame = CGRectMake(navigationController.view.superview.frame.origin.x, navigationController.view.superview.frame.origin.y, navigationController.view.superview.frame.size.width, 230);
But this does not work on iOS 8, not sure why? Does anyone knows what is the problem? any idea will be appreciated.
Thanks in advance.

After checking it, I could figure out the problem. After initializing the view navigation controller, its superview is nil and you can't access it right after presenting it. As a workaround, you can change the frame of its superview in the viewwillAppear of the view controller you're trying to present as you can see below:
- (void) viewWillAppear:(BOOL)animated
{
self.parentViewController.view.superview.frame = CGRectMake(self.parentViewController.view.superview.frame.origin.x, self.parentViewController.view.superview.frame.origin.y, self.parentViewController.view.superview.frame.size.width, 230);
}
This should work.

Related

Modal View is Resetting My Existing View Controller

I load a view controller in my code using a segue in UIStoryboard. Based on a few user selected options, I then hide or show a UI control using an animation. It all works fine.
- (void)showComments {
NSLog(#"Show Comments");
_commentsTextView.hidden = NO;
_commentsTextView.frame = CGRectMake(435, 266, 475, 134);
[UIView animateWithDuration:1 animations:^{
_commentsTextView.alpha = 1;
_signatureButton.frame = CGRectMake(435, 420, 475, 134);
_cancelButton.frame = CGRectMake(568, 581, 100, 44);
_finishedButton.frame = CGRectMake(676, 581, 100, 44);
}];
}
Then I am presenting a view controller created in UIStoryboard using the following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
SigningViewController *signingVC = (SigningViewController *)[storyboard instantiateViewControllerWithIdentifier:#"SigningViewController"];
signingVC.object = self;
signingVC.signatureProperty = #"employeeSignature";
signingVC.startDate = self.startDate;
signingVC.endDate = self.endDate;
[self presentViewController:signingVC animated:YES completion:nil];
When this code fires all happens as expected except for one thing: All the custom animations that hid or showed a UI control revert back. It is as if by calling the presentViewController method, it is redrawing my existing view from the UIStoryboard.
Is there a way to get it to quit redrawing/reload my existing view from the Storyboard before displaying the new view modally?
I had the same problem too. Whatever I tried to make an animation change whenever a modal closed it seemed to reset back to the original storyboard.
The solution I had to go with was to add any animation view as an outlet to the header file. Take off the view out of the self.view or main view of the view controller on the storyboard and programmatically add it as a subview. Set the frame to where you want it and all the animation positions should be the same after you end the modal. It worked for me if you need more explanation and let me know.
I had just the same problem and posted it here in a more detailed form, A user named kokx helped me a lot and the answer is documented in my question page.

How to I launch a view controller from a tap gesture

Apologies if this is a basic question but I am new to Xcode and have a storyboard app and in the storyboard (with no segue) I have a view controller with an embedded map view.
On the storyboard screen I have an image with a tap gesture linked, I have tested the tap and it works (NSLog) but I want to know how to launch my mapview view controller and also zoom to an x&y.
My code currently has
-(IBAction)handleMapTap:(UIGestureRecognizer *)sender {
NSLog(#"Tapped");
}
& I have tried;
MMMapViewController *mapViewController = [[MMMapViewController alloc] initWithNibName:#"MapView" bundle:nil];
[self.navigationController pushViewController:mapViewController animated:YES];
My view controller has a class set as MMMapViewController I have given the view controller a storyboard id of MapView (if it's required?).
I've read a lot of stackoverflow articles but can't seem to find an answer. If anyone can help I would be really grateful.
-(IBAction)handleMapTap:(UIGestureRecognizer *)sender
{
MMMapViewController *mapViewController = [[MMMapViewController alloc] initWithNibName:#"MapView" bundle:nil];
//[self.navigationController pushViewController:mapViewController animated:YES];
[self presentModalViewController:mapViewController animated:YES];
[mapViewController release];
}
It would probably help to know what self is, if it is indeed a UIViewController, then
I would make sure that self.navigationController is not nil.
You actually have the right code, as far as I can tell, but depending on your scenario, you could get away with presenting the mapView as a modal view controller.

how to retain view after addSubview of UIViewController with ARC

How to handle situation when I use ARC and add view of UIViewController?
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[someView addSubview:vc.view]; //this retain vc.view
because addSubview retain onlu view, not controller, so controller is released. Before ARC there was a way to retain controller as long as neede, but how to prevent ARC to release View Controller?
I had similar situation solved by declaring vc as property with default strong attribute.
#define AntiARCRetain(...) void *retainedThing = (bridge_retained void *)__VA_ARGS; retainedThing = retainedThing
And then call AntiARCRetain(controller);
Why would you need a new ViewController there?
You should just add your View as Subview and handle everything with the ViewController of "someView"

Xcode 4.2.1 UIScrollViews not scrolling in storyboard

So basically I have this project, where I have 4 different tab bar pages. 2 of them uses navigation controller & tab bar, and 2 are just view controllers. Now there is this one viewcontroller, which I need to add a scroll view to. So basically, I click on the item in the tab bar, it takes me to a view controller, where I can scroll down and up. I have been following Youtube Video Link, but I do not get it to work. The problem is that I use the exact code, and I change the ViewController class to the .h and .m name (ScrollViewViewController), and I put in a scroll view that has 320 x 1000, and a button at the top, but it doesn't scroll! How can I solve this problem?
Note: That if you don't know my problem, but could very detailed walk me through on how to add a scroll view to storyboards in xcode 4.2, then that would be amazing :)!
scrollerViewController.m:
- (void)viewDidLoad {
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 1000)];
[super viewDidLoad];
}
scrollerViewController.h
#interface scrollerViewController : UIViewController {
IBOutlet UIScrollView *scroller;
}
#end
And here comes a picture of the storyboard.
I need some of the code in order to really know your problem, but let me throw in my guess. You may be setting the size 320x1000 to the frame size of the scrollview by any chance? The frame size of the scrollview has to stay 320x480, and the contentSize should be 320x1000. Sorry if it was a wrong guess, but shouldn't do any harm :)
Something like this in your ViewController of the scrollView...
- (void) viewDidLoad {
[super viewDidLoad];
UIScrollView * scrollView = self.view;
scrollView.frame = (CGRect){scrollView.frame.origin, CGSizeMake(320, 480)};
scrollView.contentSize = CGSizeMake(320, 1000);
scrollView.backgroundColor = [UIColor whiteColor]; // I am setting the white background, so that the scroll indicator is visible
}
I am assuming you are setting ScrollView as the top view of the ViewController in your Storyboard as in the attached image.
I followed the exact same movie and it did not work for me either. But this movie did: http://www.youtube.com/watch?v=YBlwepYK7Zs
I followed that one and now i got it to work.
A bit late but might be more people looking for a solution to this.

Adding CPTGraphHostingView as a subview

There isn't a lot of questions about this and none of them were answered in a way that could solve my problem, still sorry if I'm asking something that was asked already.
My problem is that I'd like to use core plot to draw a graph inside a view. So I add the view on IB in my appviewcontroller.xib , but thenI can't find how to link that specific zone I just defined on IB to the file's owner.
A bit of precision: I managed to use core plot in another application, when it was the main view, but now that I want to add it to an existing application, so an existing view, it doesn't work...
And to add the new zone, I just went into IB, and dragged a view from the objects library onto my appviewcontroller.xib.
So how do I link that particular view to the code I wrote for it ?
Thanks for any help !
U have to add uiview created to self.view,then add graph hosting view to it...
Try this
- (void)loadView {
self.view =view1;
}
- (void)viewDidLoad {
[super viewDidLoad];
CPGraphHostingView *hostingView = [[CPGraphHostingView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
hostingView.backgroundColor=[UIColor whiteColor];
graph = [[CPXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
hostingView.hostedGraph = graph;
[view1 addSubview:hostingView];
Create another view(view 2) in a main view(default view let it be view)in the storyboard(xib file) and make sure it (view 2) as outlet in the header file(.h).
Drag and Connect it to the newly created view in the storyboard(xib file) so after making necessary connections in the storyboard,storyboard should be like this:
View---view (default view connected to view) and
view 2---view (new view, view 2 connected to its view).
In the loadView method of implementation file,try out these code
-(void)loadView {
[super loadView];
newView = [[CPTGraphHostingView alloc] initWithFrame: [[UIScreen mainScreen]applicationFrame]];
[self.view2 addSubview:newView];
}

Resources