MKMapview freezes when zoomEnabled=NO and call setRegion (iPhone SDK) - iphone

I am a beginner in iPhone development and I have come across a problem with MKMapView. First let my describe how to reproduce the problem.
Create a view-based application
In Interface Builder, add a MapView that cover the whole view area
Add a UIButton over the Mapview (size 50x50 is fine, put it in a corner)
Associate the MapView in IB with a MapView reference in the code
Associate the UIButton to an handling method (touch down).
Here's the code for the controller (MapTest3ViewController.h)
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MapTest3ViewController : UIViewController {
MKMapView *myMapView;
}
#property (nonatomic,retain) IBOutlet MKMapView *myMapView;
- (IBAction) zoomClicked:(id)sender;
#end
(MapTest3ViewController.m)
#import "MapTest3ViewController.h"
#implementation MapTest3ViewController
#synthesize myMapView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//myMapView.zoomEnabled = NO;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (IBAction) zoomClicked:(id)sender
{
// when zoom button is clicked, zoom on a specific region
CLLocationCoordinate2D locationCoordinate2D;
locationCoordinate2D.latitude = 35.6994;
locationCoordinate2D.longitude = 139.78;
MKCoordinateSpan coordinateSpan;
coordinateSpan.latitudeDelta = 1;
coordinateSpan.longitudeDelta = 1;
MKCoordinateRegion coordinateRegion;
coordinateRegion.center = locationCoordinate2D;
coordinateRegion.span = coordinateSpan;
[myMapView setRegion:coordinateRegion animated:YES];
}
#end
I have set scrollEnabled=YES, zoomEnabled=YES and showUserLocation=YES in IB. The application WORKS fine. I can zoom using pinching, I can scroll, whenever I push the "Zoom" button the view area moves to the region defined in zoomClicked.
The problem
When I set zoomEnabled=NO in viewDidLoad, I can no longer zoom using pinching gestures which is fine. However, if I "play" with the map, scrolling, trying to zoom(which of course doesn't work), then push the zoom button the map freezes and I can no longer scroll or do anything.
Again, how to replicate the problem (zoomEnabled=NO)
After application loads, the map of the entire earth appears. Do some pinching gestures in and out, scroll the map. (Zoom doesn't work which is expected)
Push the zoom button which should set the map the a specific region (in the code Tokyo, Japan) -> the map freezes.
My setup
iPhone OS 4.0.1/iPhone 3GS/XCode 3.2.3 64bit/Testing done on the phone itself.
Any help would be greatly appreciated.
Thanks.

Related

Following is my viewcontroller ,it has margin from top in phone with notch display. What need to be done?

Image Of the View Controller On Phone I have tried setting modalPresentationStyle to fullscreen but did not work.
It is working beautifully in devices without notch display. In Storyboard changed the presentation of viewcontroller to fullscreen but still didn't work.
#import "DocumentServicesViewController.h"
#import "SendItToUsViewController.h"
#interface DocumentServicesViewController ()
{
NSMutableDictionary *getMyRecordDataDict;
BOOL IsGetMyRecordsServiceAvailable, IsScanAtHomeServiceAvailable;
}
#end
#implementation DocumentServicesViewController
#synthesize alertClassObject,FromPushNotification;
- (void)viewDidLoad {
[super viewDidLoad];
[self setImages];
[self allocAllObjects];
if (!FromPushNotification)
{
[self getDocumentMenuDetails];
}
else
{
ScanAtHomeViewController *scanObject = [[ScanAtHomeViewController alloc] initWithNibName:#"ScanAtHomeViewController" bundle:nil];
scanObject.FromPushNotification = YES;
[self.navigationController pushViewController:scanObject animated:YES];
}
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
if(((int)[[UIScreen mainScreen] nativeBounds].size.height)==2436) {
[self setStatusBarView];
}
}
// Do any additional setup after loading the view from its nib.
}[Sample image of viewcontroller][1]
I don't know you layout, also I don't know expected result,
I may guess You want light-gray status bar, you probably have top constraint to superview with 20pt constant.
if I'm right remove this constraint and add another one to safearea top with 0pt constant.
Read more about safe area here

View not scrolling when simulator set to landscape mode iOS

I went through many blogs, stack flow questions and googled alot, but didn't get any solution to get my ScrollView work. I don't know why but my ScrollView works in portrait mode but not in landscape.
I am developing using xcode 5 for ios 7 devices. I developed my screen using storyboard. I added a ViewController on storyboard, removed the default UIView it contains, and added a ScrollView. In that ScrollView I added my subviews. Then I referenced the ScrollView to the scrollview object in the outlets.
This is my LoginViewController.h
#import <UIKit/UIKit.h>
#interface LoginViewController : UIViewController
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
#end
This is my LoginViewController.m
#import "LoginViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
#synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
My scrollview scrolls when in portrait mode but not in landscape. Please help me. Thanks in advance.
Reset scroll view content size on screen orientation:
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
Scroll view frame most probably will change so you need to re-set content size.
if you have auto layout on set content size inside layoutSubviews:
- (void) layoutSubviews
{
[super layoutSubviews];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
}
Note
Content size supposed to be larger than scroll view size. to scroll right?
You want to add scrolling in scroll view check scrollView height.
If scrollView.height > scrollview.content.height scrollview did not scroll. But scrollView.height < scrollview.content.height scrollview will scroll....
So, the scrollview's content height is greater than the scrollview height is necessary for scrolling..
Therefore, you should do something like this:
scrollView.contentSize.height=scrollView.height+50

Why won't UIScrollView scroll fully after adding objects? Using storyboard, ARC, and Xcode 4.5.2

So, I know there are similar questions to mine, but maybe not exact (so please don't mark me down -- just warn me or something). I have searched for days for the solution to this SIMPLE issue. Using storyboards, ARC, and Xcode 4.5.2, I simply need to put a bunch of labels inside a UIScrollView and have it scroll vertically. I've tried so many combinations of setting frame sizes and content sizes within viewDidLoad, viewDidAppear, and viewWillAppear, but to no avail. The scroll view scrolls perfectly when there's nothing inside of it, but when I add labels to it, the scrolling only scrolls a very short section.
Note: I need to use auto layout, otherwise my whole project will get messed up.
Here's my current code...
.h file:
#import <UIKit/UIKit.h>
#interface MortgageRatesViewController : UIViewController <UIScrollViewDelegate, UIScrollViewAccessibilityDelegate>
- (IBAction)backButton:(id)sender;
#property (strong, nonatomic) IBOutlet UIView *mortgageView;
#property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
#end
.m file:
#import "MortgageRatesViewController.h"
#interface MortgageRatesViewController ()
#end
#implementation MortgageRatesViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//-------------------------------------------------------
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"appBackgroundColor.png"]];
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(0, 809)];
}
//---------------------------------------------------------------
//---------------------------------------------------------------
//-(void)viewWillAppear:(BOOL)animated{
//
//
// [super viewWillAppear:animated];
//
//
// [self.scrollView setFrame:CGRectMake(0, 0, 320, 808)];
//
//
//}
//---------------------------------------------------------------
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.view addSubview:self.scrollView];
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:CGSizeMake(0, 809)];
}
//-------------------------------------------------------------
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)backButton:(id)sender {
[self dismissViewControllerAnimated:YES completion:NO];
}
#end
Note: having viewWillAppear commented out has made no difference.
EDIT: I POSTED THE SOLUTION BELOW. HOPE IT HELPS OTHERS!
After days of research, it's funny I actually found the solution just minutes after posting this question! So, for my situation I simply had to add this bit of code, and it worked:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.scrollView setContentSize:CGSizeMake(320, 808)];
}
It seems to be working perfectly now. Please, anyone, let me know if this is a poor way of doing it, because I'm new to this and I would love any help. Otherwise, I'll leave it and hope this can help other people! Thanks!
SOLUTION with Storyboard + Autolayout (no code):
Vertical scrolling example that starts from top-left corner:
Set the top+leading constraints of the first object (subview)
Chain up every object till the last one
The most important - set the bottom constraint to the scroll view so it's hooked up top to bottom.
Set the width of the scroll view - either a specific "magic number" or a better way - connect the trailing constraint of a subview that has a set width - if there's non I usually set a label's width = screen width - side paddings => standard(20)+UILabel(280)+standard(20) - this way the scroll view knows exactly its content's width, otherwise you'll get an "ambiguous width" warning.
*Needs constraints' adjustments if horizontal scrolling is desired.
your scrollview's frame is not the scrollable size.
Check out contentSize
Set frame to its superview.bounds then set content size to the scroolview's scrollable area.
Also I dont know that the background will scroll.
You will want to add subview's to the scrollview itself.
It should scroll its own subviews. but it will not scroll itself :)

ADBannerNavigation white space where Ad should be when popping view controller

I downloaded iAdSuite and looked into ADBannerNavigation.
Inside, I changed the RootViewController to subclass TextViewController in order to take advantage of the iAd banner resizing. I want to display ads on the RootView as well.
This is now RootViewController.h:
#import <UIKit/UIKit.h>
#import "TextViewController.h"
#interface RootViewController : TextViewController
#end
Everything else is the same. When I compile and run, no ads show up in RootView, and when I click into TextView, ads suddenly show up.
When I click to go back, there is now white space in RootView.
WHY?
How do you remove the white space?
Found the error in how I was removing the ADBannerView.
iAd Suite tells us to:
Note: If your application has multiple tabs or views displaying an iAd banner, be sure to share a single instance of ADBannerView across each view. Then, before your users navigate to a new view, set the shared instance’s delegate property to nil, remove it from the old view hierarchy, then add the same instance to the opening view and set its delegate to the appropriate view controller. The "AdBannerNavigation" sample shows this technique.
So, in my iADBannerView.m, I have:
- (void)viewWillDisappear:(BOOL)animated{
[self removeADBannerFromView];
[super viewWillDisappear:animated];
}
- (void)removeADBannerFromView{
NSLog(#"ad removed from view");
ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];
}
- (void)dealloc{
// we are being called here when we navigate away from this view controller,
// so go ahead and reset our AdBannerView for the next time
//
ADBannerView *adBanner = SharedAdBannerView;
adBanner.delegate = nil;
[adBanner removeFromSuperview];
[contentView release]; contentView = nil;
[super dealloc];
}
By setting breakpoints, I saw that by exiting a view, viewWillDisappear was being called on view1, then viewWillAppear on view0 and then dealloc on view1.
The problem was that view1 already removed the ADBannerView from the view, so [adBanner removeFromSuperView] was removing the Ad from view0.
Problem solved by removing offending code from the dealloc method.

basic xcode iphone app not working, button clicks to change text?

I've followed the tutorial below, it basically just tells you to create a button and a label. When you click the button the label should change to some text.
http://paulpeelen.com/2011/03/17/xcode-4-ios-4-3-hello-world/
It runs but it shows a blank screen. When you click the screen it goes blue like the entire page is a button. I think it's loading the mainwindow.xib file instead of the default ViewController.xib
Any ideas, I'm obviously missing something?
Thanks
EDIT
#import <UIKit/UIKit.h>
#interface fun_buttonViewController : UIViewController {
UILabel *textLabel;
}
#property (nonatomic, retain) IBOutlet UILabel *textLabel;
- (IBAction)changeTheTextOfTheLabel;
#end
The implementation:
#import "fun_buttonViewController.h"
#implementation fun_buttonViewController
#synthesize textLabel;
- (void)dealloc
{
[super dealloc];
[textLabel release];
}
- (IBAction)changeTheTextOfTheLabel
{
[textLabel setText:#"Hello, World!"];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
You probaly made a simple mistake. I would go through the example again and see if you did anything diffrently.
If you post your code or upload your files somewhere I could take a look at it for you.
Its kind of hard to guess what the problem is without seeing what you actually did^^
It was as I suspected. It's not a code problem, since the code is fine. The tutorial is also perfectly fine. I thought it had to do with the XIB, and when I looked into there this is what I saw:
In your MainWindow.xib, you had a button loading from the ViewController. Why? I don't know.
It might have been placed there by accident. Here's a screenshot of what I mean:
The left view is from your view controller. See the UIButton loading in the ViewController? It is blocking the rest of the view. Just delete the button that's loading OVER your view, and it works perfectly. The view hierarchy, was essentially blocked by that massive extraneous button.
It could be anything from your XIB (most likely) or from your app delegate.
Are you sure you connected the buttons properly?
Send us your code/zip of the project so far.