I would like to implement a half UITableView half MapView UIView with a button in the middle - objective-c

Well, this is what I want to do in my app: I would like to implment a UIView with a map on the top half of the screen and a tableview on the other half with two buttons in the middle. If I press one of the buttons the map will get fullscreen and if I press the other one the tableView will fit all the screen.
Any suggestion?

In one view controller like a UINavigationController create an MKMapView with a frame the size of the top half of the view and add it as subview of your view controller. Then I would create a UIToolbar to hold your buttons and make the top of it's frame line up with bottom of the MKMapView. Finally create a UITableView with it's frame just below the others (make sure you hook up it's delegates).
Then assign the target of your UIBarButtonItem that makes the map go fullscreen to a method that animates the frames of all three views like this:
[UIView animateWithDuration:0.24
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:(void (^)(void)) ^{
self.toolbar.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN, 320, TOOLBAR_HEIGHT);
self.mapView.frame = CGRectMake(0,0,320,MAP_HEIGHT_FULLSCREEN);
self.tableView.frame = CGRectMake(0, MAP_HEIGHT_FULLSCREEN+TOOLBAR_HEIGHT, 320, MAP_HEIGHT_FULLSCREEN-MAP_HEIGHT);
}
completion:^ (BOOL finished){}
];

Create both views how you are planning, On one button click, change the frame of one view to fit the full screen, if you click the other button, do the same thing to the other view.

Related

My UIScrollView shifts after dismissing Modal View

I've got a UIScrollView on my main ViewControler. When it initially loads from startup the UIScrollview is placed correctly but when I go to a modal view and then dismiss that modal view the UIScrollView shifts up several pixels from the position that my UIScrollView was at when I loaded the modal view (the amount of shift seems to be relative to the position of the UIScrollView). So in other words if my UIScrollView was all the way to the top it loads correctly if I was scrolled all the way to the bottom when I go to a modal view and then go back it seems to have shifted up approximately 20 to 30 pixels cutting the top of the content off in my UIScrollView.
I cant figure out why its loading differently depending on the amount I've scrolled before loading the modal view.
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat scrollFrameHeight = [[UIScreen mainScreen] applicationFrame].size.height;
CGFloat scrollFrameWidth = [[UIScreen mainScreen] applicationFrame].size.width;
scrollView.frame = CGRectMake(0, 0, scrollFrameWidth, scrollFrameHeight);
}
FYI... I've tried using static numbers in place of my variables and I still get the strange shift.

Force Subview to fill parent

I have some subviews that I place inside each of my tab bar's view controllers. Right now I'm sizing it with a pixel count but it only works on the iPhone 4 and 4s and not the iPhone 5 because of the longer screen size. I could check for the device and then size it that way but I feel like there has to be an easier way to do this.
viewController1.view.frame = CGRectMake(0, 0, 320, 460);
I colored the subview yellow so it's easier to see.
You should NOT change frame of tabbar's content view controller's view. UITabBar takes itself care of sizing the child view controller's frame properly.
If you want to add subview to content view controller (controller under some tab) and make that view to always automatically resize with the controllers main view (self.view), you can use combination of superviews frame and autoresizing.
Example code (you can do this in - (void)viewDidLoad for example):
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:view];
If you want to do this by setting frame than DO this:
[childView setFrame:childView.superview.bounds];
The master view in your view controller should already be the size of the usable space on the sceen. In general, if you want a view to be the same size as it's parent, you can use view.frame = view.superview.frame, though I doubt that would be a good idea to call on the view controller's view.

Set a UIPickerView to bottom of UITableview regardless of scroll position

I'd like to present a UIPickerView snapped to the bottom of a UITableView regardless of where it is scrolled.
Currently I have a UIPickerView added to a UITableView that I present when a button is pressed, but when I scroll the table the UIPickerView goes out of view, and if I'm scrolled out of range of where I've presented it, the UIPickerView appears to have never been called.
Does anyone know how to accomplish this?
Thank
The use of UITableViewController is great unless you need to add subview that don't scroll with the table view. It can't really be done. The solution is to use a UIViewController instead and add your own table view, setup the table view dataSource and delegate protocols and replicate the basic table view controller plumbing.
Once your view controller works like a normal table view controller again, you can now add subviews to the view controller's view that won't scroll with the table.
if u add tableview programatically
SearchtableView.frame = CGRectMake(450, 90, 318, 600);
SearchtableView = [[UITableView alloc] initWithFrame:CGRectMake(623, 90, 400, 400)style:UITableViewStyleGrouped];
[self.view addSubview:SearchtableView];
//belove the tableview//
//Add UIPickerView to the self.view]//
Something told me that there must be a simpler alternative to the answers that I'd been given, and I found a solution.
I decided to find the y coordinate of the scroll point using scrollViewDidScroll: and then animating the UIPickerView to the desired location.
...
[UIView beginAnimations:nil context:NULL];
CGFloat pointY = self.scrollPoint.y;
[self.sortPicker setFrame:CGRectMake(0, pointY + 200, 320, 216)];
[UIView commitAnimations];
...
The UIPickerView will only appear if the scroll has been stopped so it's necessary to implement a method to stop the scroll on touch:
- (void)stopScroll:(UITableView *)tableview
{
CGPoint offset = tableview.contentOffset;
[tableview setContentOffset:offset animated:NO];
}
This will allow you to display and dismiss the UIPickerView at any moment at any given destination.

Resize UIView from point with animation

I have UIButton on view, when I taped on this button I want to create new view and display it on iPad screen, how I can view this view like growing from button to full screen ?
Next time actually show some effort with what you have tried etc when asking for help
- (void)buttonTapped:(UIButton *)button;
{
UIView *expandingView = [[UIView alloc] initWithFrame:button.frame];
expandingView.backgroundColor = [UIColor redColor];
[self.view addSubview:expandingView];
[UIView animateWithDuration:.25f
animations:^{
expandingView.frame = self.view.bounds;
}];
}
On the button click event.
Create the view with frame with size zero and orgin as center of
button
2.add to mainview
3.Then using animation block change
the frame to orginal
What are block-based animation methods in iPhone OS 4.0?
use this qn to find how to add animation

Releasing invisible buttons with images in UIScrollView

I have main UIScrollView with lots off buttons which i create like this:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]
every button have an image:
UIImage *fileImage = [UIImage imageNamed:#"sun.png"];
[myButton setBackgroundImage:fileImage forState:UIControlStateNormal];
Buttons count could be more than 500. So i need to remove from UIscrollView invisible buttons with images to save memory ?
I believe in this method i need to calculate when UIscrollview is stopped scrolling and for example 20 images are invisible, then i need to remove them and reduce scroller contentOffset.
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
}
Maybe some one could give me tips on this. Or even have a good bookmarked tutorial.
I created a similar thing to this using UIViews in a UIScrollView. When the UIScrollView loads, I set the contentView size of the scrollView to be the size of all the views but only loaded the views that can be seen, then when the user scrolls i added the previous/next views and removed the hidden views.
This question helped me: How to implement UIScrollView with 1000+ subviews? especially akosma's answer