iPhone: calling UIImagePickerController 'moves' the view that calls it - iphone

I recently encountered very strange behaviour with the UIImagePickerController. On our main view we have a button that calls the image picker controller. If you hit cancel on the image picker, I simply dismiss the controller, and for some reason or another my main view moves down roughly about the height of the status bar (which is not turned off on the main view, left at default gray). Anyone else encounter this?

Yeah I saw that post, and it didn't fix my issue. What I ended up doing was adding this in my app delegate before adding my first view to the window:
CGRect theRect = mainMenuController.view.frame;
float statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
theRect = CGRectOffset(theRect, 0.0,statusBarHeight);
mainMenuController.view.frame = theRect;
This fixed it completely.

This problem is annoying, its been discussed before, check it out Contents of UIScrollView shifted after dismissing ModalViewController

Related

Custom UIView covering UITabBar on iPhone but not iPad

I'm creating a custom uiView that covers the window. It acts kinda like a decoy uiview in a navigation controller. So I had to do it this way to cover the navigation bar.... long story...
Here is how it gets setup.
self.searchPopDown.frame = CGRectMake(0, 20, self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height-20);
self.searchPopDown.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
The 20 is to compensate for the status bar.
Then I simply add the view as a subview to the app window.
//this will add the view ontop of a modalViewController and support rotation!
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
if ([[[window subviews] objectAtIndex:0] isKindOfClass:[SVProgressHUD class]]){
//There is a chance that the window will be the SVProgressHUD in this case we need to get the main window.
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
[[[window subviews] objectAtIndex:0] addSubview:self.searchPopDown];
All of this works great and dandy. However I've noticed something strange. On the iPhone this view will end up being resized to cover the UITabBar at the bottom of my app. But on an iPad it gets resized correctly to compensate for the UITabBar. Any ideas why?
Thanks
=================
Here are some screenshots describing the issue. This is what it looks like when the view loads with the fake view onto of everything. The view shows up (as far as the user is concerned just the view and the buttons on the navbar have changed slightly. When you have searched this fake view disappears revealing the real view below with the search results. ON the ipad the fake view doesn't cover the tab bar. Why doesn't it do this on the iphone also?
==========
edit 2
Another weird thing. I'm generating log messages to get what the height of the navigation controller is. It changing by 49 depending on if I display normally or present as a modal view and there is no tab bar.
So the log says 431 should be the correct height. I go into interface builder and setup a simple pink view that's measured at 431 and it looks great :) However when I manually set the size to 431 it doesn't work. I have to set the size to 298 to get this to work correctly ... weird...
See the pink bar? It is literally 431 tall... and the log says that's what my view is.. but it's not :/
============
edit:3
I have traced this to the imagebackground with the bubble logo resizing incorrectly...
I had to check "clip subview" on the parent view that the imageview was in... fixed the problem...

Disabling Userinteraction of all views besides one

I am new to iphone.I am struck in my project at some task that is I have a view controller in that lot of buttons and webview is there when i click on webview it recognize the gesture and set some size to webview but tere is some buttons are visble in the screen at that time i want to disable the interaction of all other things in view controller except the webview.Similarly like as UIAlertView there also userinteraction disabled with all other things except the alertview.If any body know this please help me...
This will disable user interaction on all views except for the uiwebview
for(UIView *currentView in self.view.subviews)
{
if([currentView isKindOfClass: [UIWebView class]])
{
currentView.userInteractionEnabled = NO;
}
}
You can set the property userInteractionEnabled=YES //or No of any UI Object.
You can place your webview on a transparent view ( let's name it "coverView" ) , which frame equals to screen's frame. When you present the coverView (with the webview sticked to it) the user will see everything around the webview (because the coverView is transparent), but any interraction with other objects around the webview will be blocked by the coverView.

Non Selected Tab Bar View Controllers aren't resized when device rotated

I'm having problems making my app iPad compatible.
I have an implementation of a custom Tab Bar, based on the post here http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html
That all works fine apart from when the device is rotated. The currently selected view rotates and resizes perfectly. Every other view rotates but does not resize to fill the space. There is a large white column down the right hand side.
I've tried adding
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;
to the tab controller view.
I've added similar code to the tab's views viewDidLoad methods.
I've tried to make the willRotateToInterfaceOrientation call all the subviews rotation methods but still no luck.
Any suggestions would be more than welcome at this stage. I'm hoping i'm not overlooking something obvious but i might be. I've been at it for a few hours now
Screenshot 1 -
Screenshot
Ok I Solved this problem.
What I had to do was manually call a resize on all the sub views. - i added a changeFrameSize function to each sub view (just so it made the code look a little nicer)
Oh and when adding views as sub views always use belowSubView method -
[self.view insertSubview:viewController.view belowSubview:tabBar];
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[(ViewControllerClass *)[viewControllers objectAtIndex:0] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:1] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:2] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
}
So because the selected view controller was always rotated and resized to the correct size, once it had rotated and adjusted i simply passed the same parameters to the sub views so they would resize too.

MKMapView inside a UIScrollView doesn't move with swipes

I've got a detail view with various labels and such providing information about a place (address, phone, etc.). The information provided is taller than an iPhone screen so they're all in a UIScrollView (itself inside a UIView) that allows you to swipe up and down to see everything.
I also have an MKMapView inside the scrollview. When it's not attached to anything in Interface Builder it moves up and down with the scrollview, as it should, staying in it's correct relative position to the other controls in the scrollview. You can play with the map, zooming and panning it, etc. and it shows your current location by default.
However, as soon as I hook it to an MKMapView variable in IB, the mapview no longer scrolls with the scrollview. Instead it literally just sits in the position it's originally displayed in (bottom of the view, with a little of the map hidden below the bottom of the view) and the scrollview scrolls up and down behind it.
What's happening here? I've tried changing a bunch of the mapview's and scrollview's properties in IB, but it has no effect. The only thing I haven't tried is just creating the mapview entirely in code, but that doesn't seem like an obvious solution.
EDIT: Sorry to everyone about the expired bounty. I got hung up in other areas of the project and couldn't get back here until now. I didn't know it would expire.
FURTHER EDIT: Well, I figured out my problem. For reasons completely unknown to me I had
[self.view addSubview:mapView];
in the viewcontoller's ViewDidLoad. Once it was hooked up then that line of code would (obviously) make the map a subview of my of view, effectively yanking it out of the scrollview.
Stupid mistake, sorry to have wasted your time (and the bounty). I'll delete this question after I think the answerers have had a chance to see the result.
Looking like as you are using the ScrollView,you need to scrolling facility in your DetailView.
Instead of using the ScrollView ,I had an alternative of this ....
You can try your hard luck by using the TableView instead of ScrollView.
Just take all the labels and mapView in a single View and then put that view in the header of the TableView.
like this :
UITableView
--> View
------>All Labels // Inside the singleView
------>MKMApView // At bottom of the View
Still You can play with the map, zooming and panning it, etc. and it will show your current location by default.
Hope this alternative can solve your problem.......
All the Best
If hooking up an outlet in IB is breaking an otherwise working view, you might be able to try this to locate the view at runtime:
- (UIView *) findClass:(Class) aClass inView:(UIView *) aSuperview {
for ( UIView *view in aSuperview.subviews ) {
if ( [view isKindOfClass: aClass] ) break;
if ( ( view = [self findClass: aClass inView: aSuperview] ) ) break;
}
return view;
}
- (void) viewDidLoad {
MkMapView *map = [self findClass: [MkMapView class] inView: self.view];
}
I figured out my problem. For reasons completely unknown to me I had
[self.view addSubview:mapView];
in the viewcontoller's ViewDidLoad. Once it was hooked up then that line of code would (obviously) make the map a subview of my of view, effectively yanking it out of the scrollview.
Do you have setContentSize property set to the content's size in the viewDidLoad method of the UIViewController?

iPhone + UIScrollView

I have a UIScrollView on screen.
Scroll view contains a view in which are UIButtons.
The problem is that while scrolling the view, if I press any button in between my scroll view will either bounce to top or bottom of the screen, it means it will not remain at place where I have pressed the button.
Take a look at the UIScrollViewDelegate class. You want to disable the buttons while
scrolling begins enable it when the scrolling is done.
I've reproduced the situation you've described in your question (at least I think so): a UIScrollView, a UIView inside the UIScrollView and an UIButton inside the UIView.
I tried taping touching the scroll view and moving my finger across the button and didn't get it to bounce to the top or anything like that. I also tried tapping the button after scrolling the scroll and it had no side effects too.
So my guess is that what you are dealing with is something like this: a UINavigationController with you UIScroll-UIView-UIButton UIViewController as a root view controller; after being tapped the UIButton pushes a new UIViewController to the UINavigationController; then you go back to the previous UIViewController in the UINavigationController stack and this is when you lose you scroll position.
If my guess is right than here's what you need to do.
Before pushing a new UIViewController save you scroll view's current content offset with the following code:
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromCGPoint(theScrollView.contentOffset) forKey:#"ScrollViewLastContentOffset"];
And after you get back to you UIScrollView UIViewController use the following code in you viewWillAppear: method:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults stringForKey:#"ScrollViewLastContentOffset"] != nil) {
theScrollView.contentOffset = CGPointFromString([defaults stringForKey:#"ScrollViewLastContentOffset"]);
[defaults removeObjectForKey:#"ScrollViewLastContentOffset"];
}
}
Even if my guess wrong please do comment on my and Alan's answer and confirm/refute them for us to be able to help you. Would you mind also providing more details on your problem so we wouldn't need to guess what's going on exactly anymore.
If I understand this correctly, your buttons are inside the scrollview? And when pressed you want them to stop the scrolling or move the scrollview to a specific point? Such as the top or the bottom? If so, use myScrollView.contentOffset = CGPointMake(0, 0); and specify the x and y values you need. So (0, 0) in that example would be the top left.
You might also want to try [myScrollView setContentOffset:CGPointMake(0, 0) animated:YES]; if you want to animate this transition.