There are few questions regarding this topic in stackoverflow. But none of the solutions are working for me.
I have a requirement to show pop up when user clicks on the row of a table view. Again this pop-up should contain a tableView. Since Apple recommandation is not use tableView inside a alertView,So, I need to use normal UIView with lesser size.
UIView is drawn using storyboard.
Programmatically I am trying following code to reduce the size.
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect newFrame = self.view.frame;
newFrame.size.width = 200;
newFrame.size.height = 200;
[self.view setFrame:newFrame];
}
But it is not working.
CGRect is not only width and height, its also x and y.
So do this:
CGRect newFrame = CGRectMake( self.view.frame.origin.x, self.view.frame.origin.y, 200, 200);
self.view.frame = newFrame;
This does only effect the width and height.
Probably the View that you are trying to modify is the one attached to the UIViewController via Storyboard, you will not be able to modify that one, try creating another one either with Storyboards or programmatically.
Since you are requirement is to display a popup , I would suggest you if its iPAD then go ahead with UIPopoverController and if its iPhone then just create a new full screen UIView with the transparent background (clear background) and then create one more UIView with new frames and make sure the frame size is in middle and attach it(Add subview) .
Also the procedure what you is doing won't work.Create a new UIView and change the frame and then attach or add subView to your main View
This will solve your issue.
I think you are looking for UIPopOverController with tableView..
Refer this tutorial
http://www.raywenderlich.com/29472/ipad-for-iphone-developers-101-in-ios-6-uipopovercontroller-tutorial
Related
I have a container view which is equally divided between two UIViews like this:
The portion in black is my UIView 1, which I am currently not using. My UIView 2 contains a UISegmented Bar and a UITableView.
The hierarchy of my views look something like this:
Now, my requirement is I want to resize my view2 to cover entire container view dynamically and view1 to go away based on some condition. Currently I am not worried about that condition, I just tried to resize my view2 using the following code inside - (void)viewDidLoad
CGRect newFrame = self.view2.frame;
newFrame.size.width = 200;
newFrame.size.height = 200;
newFrame.origin.x=0;
newFrame.origin.y=0;
[self.view2 setFrame:newFrame];
Here view2 is the outlet to my view2 in interface builder.
But, nothing is changing from the above code. I tried to find any other way but had no help. So please help me find out my mistake in my current technique or tell me how some other technique to do it.
Thanks in advance!
The code to change frame seems fine, just remove the view from superview, set the frame and add to superview again programmatically.
[self.view2 removeFromSuperview];
// set the frame
CGRect newFrame = self.view2.frame;
newFrame.size.width = 200;
newFrame.size.height = 200;
newFrame.origin.x=0;
newFrame.origin.y=0;
[self.view2 setFrame:newFrame];
//add self.view2 again wherever it was
[myView addSubView:self.view2];
This is what is occurring in gif form:
http://makeagif.com/SAcOBQ (Sorry about quality)
Notice the UILabel at the top takes a moment to move down into its proper location.
No constraints that are ambiguous, I am very confused. Using XCode 6 GM.
The UIImage is adjusting fine.
Another ViewController that a segue leads to has a UILabel at the same position/same constraints and has no issue. That particular VC is not embedded in a pageviewcontroller.
It could be a problem with the topLayoutGuide. The height of the statusbar is ignored when the view's frame is offscreen (not {0,0}) when adding to the view hierarchy. I think it's a bug in Xcode 6.
I solved this with a workarround like this:
CGRect frame = self.view.frame;
CGRect frameSave = frame;
frame.origin.x = 0;
frame.origin.y = 0;
self.view.frame = frame;
[theContainingView addSubview:self.view];
self.view.frame = frameSave;
I don't know if it's possible to use this in UIPageViewController. But when You find a way it will workaround the bug.
Consider the following UIView "MainView":
The view includes a Container View which in turn houses a UITableView controller. The container view's y coordinate starts just beneath the gradient bar. The UITableView includes the section footer at very bottom with the 'STU' label and 'chart' button.
When the UIView loads, and up-to-and-until any interaction with the tableView, MainView's dimensions are:
Frame: 0.000000x, 0.000000y, 568.000000w, 268.000000h
I have a delegate protocol set up such that tapping the chart button in the tableView will create a new view in MainView for a shadow effect via a method performing:
CGRect newFrame = self.view.frame; // self = MainView
newFrame.size.width = 100;
newFrame.size.height = 50;
UIView *backgroundShadowView = [[UIView alloc] initWithFrame:newFrame];
backgroundShadowView.backgroundColor = [UIColor blackColor];
// Do Animation
The important part above is the 'newFrame' CGRect. For some reason after interacting with the table view by tapping the chart button, or even scrolling or tapping a row, self.view.frame suddenly has the following dimensions:
Frame: 0.000000x, 52.000000y, 568.000000w, 268.000000h
And so the shadow view appears as follows, with a y origin much farther down than where it would be expected to start, just above the gradient bar.
I've adjusted the width and height of the "shadowview" for this question; normally it would be 568x268, but would extend 52 units off screen on the bottom because of this issue.
52 units is exactly the height of the statusbar (20) + navigationbar_in_landscape (32).
Of course I could manually adjust the frame dimensions, but I do not want to. I want to know why the view's frame is changing unexpectedly.
For the life of me, I cannot figure out why the view becomes suddenly offset. Any help is appreciated!!
Two comments.
(1)
This code was probably always wrong:
CGRect newFrame = self.view.frame; // self = MainView
newFrame.size.width = 100;
newFrame.size.height = 50;
UIView *backgroundShadowView = [[UIView alloc] initWithFrame:newFrame];
You surely want to define backgroundShadowView's frame in terms of self.view's bounds, not its frame as you are doing in the first line here.
(2)
The change in self.view.frame is probably illusory. You are probably checking this initially in viewDidLoad. But that is too soon; the view has not yet been added to the interface, and so it has not yet been resized to fit the surroundings.
Using Storyboard I have my UITableView drawn starting at the top of my ViewController and as wide and tall as the VC. When i run my app it lowers the UITableView roughly 75 pixels. I've tried to turn on/off auto layout and every auto-sizing option imaginable. I've tried changing the device toggle from iphone 5 to 4. I've tried adding support to rotate the interface just to rule that out too.
The only way i can make the table stay at the top of the page is to manually edit the UITableView's origin frame in my viewDidLoad statement.
//myTable is the UITableView in question
CGRect newFrame = self.myTable.frame;
newFrame.origin.x = 0;
newFrame.origin.y = 0;
self.myTable.frame = newFrame;
I am using xCode 4.6.1. Anybody else have this problem and know a solution? Thanks!
Enable autolayout.
Select table
At the bottom right. By the arrows in The interface builder set the border to top of superview (a little button that looks like it has an H in it)
Make Sure your tableView size is as per in my attached Image.
**//Do your tableView frame size in viewWillAppear**
-(void)viewWillAppear:(BOOL)animated
{
CGRect newFrame = self.myTable.frame;
newFrame.origin.x = 0;
newFrame.origin.y = 0;
self.myTable.frame = newFrame;
}
Sample Image
Hopes its useful for you..:)
I am building an app with a stream of social content and am trying to get the behavior of how instagram does it's stream in app. So basically a top header that scrolls off the screen but bounces between that and the content. I can make the top header scroll off the screen and I can make the view not bounce but I want to use Pull to refresh and that ends up going above the "faux" nav bar UIView. I know that a normal Navbar will produce this but this one that scrolls off is a different story.
Currently I have a UITableview that has a UIView above the UITableViewCell and everything works great except the bounce happens above the UIView. I figure I need to get the UIView above the UITableView however in the UITableViewController the storyboard won't allow me to place the UIView above the UITableView.
Any ideas???
Thanks
Well I finally got this all to work so I thought I would post the Answer for everyone.
Basically I set a standard Navigation bar and then on scrollViewDidScroll I get the offset of the scrolling and change the frame based on that. This seems to work perfectly, see below for my scrollViewDidScroll method.
- (void)scrollViewDidScroll:(UIScrollView *)sender {
//Initializing the views and the new frame sizes.
UINavigationBar *navbar = self.navigationController.navigationBar;
UIView *tableView = self.view;
CGRect navBarFrame = self.navigationController.navigationBar.frame;
CGRect tableFrame = self.view.frame;
//changing the origin.y based on the current scroll view.
//Adding +20 for the Status Bar since the offset is tied into that.
navBarFrame.origin.y = MIN(0, (sender.contentOffset.y * -1)) +20;
navbar.frame = navBarFrame;
tableFrame.origin.y = MIN(0,MAX(-44,(sender.contentOffset.y * -1)));
tableView.frame = tableFrame;
}
Also you will want to make your TableView 44px taller to compensate for the scrolling otherwise your frame will not be big enough. I just did this in viewWillAppear and made the frame bigger.