MKPointAnnotation is overlaying my MKMapView - objective-c

This is the problem and what i'm trying to achieve
http://i.stack.imgur.com/XpDQn.jpg
This is what i tried to achieve my goal
http://i.stack.imgur.com/lF5hy.png
and my didUpdateLocations delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation* location=[locations lastObject];
MKPointAnnotation*annotation=[[MKPointAnnotation alloc]init];
annotation.coordinate=location.coordinate;
annotation.title=#"Me";
annotation.subtitle=#"Current location";
MKCoordinateRegion region;
region.center=location.coordinate;
if(myLocation!=nil){
[_mapAsset removeAnnotation:myLocation];
myLocation=nil;
}
[_mapAsset addAnnotation:annotation];
myLocation=annotation;
[self zoomToFitMapAnnotations:_mapAsset];
}
As you can see in ScreenShot, my MKPointAnnotation is overlaying my MKMapView.I tried to put my mapView in another UIView (to use it like container) but it didn't work. I believe reason why this happening is beacuse I'm putting my annotation in code which means on all layers.
I'm using iOS7.1 SDK and Xcode5. Any advice can be useful.
Thanks in advance

Thanks to #Evan_Mulawski and answer here
I finally did what i tried.
First of all i deleted all of my mapview and its containerview's attributes like setShadowColor,cornerradiues,masksToBounds e.g.
And also deleted what i did in my storyboard to make them fresh new.
Then i added these code
[[_viewContainer layer] setShadowOpacity:0.55f];
[[_viewContainer layer] setShadowRadius:15.0f];
[[_viewContainer layer] setCornerRadius:8.0f];
[[_viewContainer layer] setBorderWidth:1.0f];
and fixed my issue. Thanks for helps

Related

UI Code in viewDidLayoutSubViews doesn't render correctly at runtime

I have recently been battling with my view controller to set the correct dimensions of a border on a UIView.
*edit, this is for a static tableview (i am using it as a form). I am aware of rounding cells in a .xib and reusing the cell however I am not reusing cells, this approach would not be useful to me.
I have a screen with a static tableview which is embedded within a UIView and displayed on a main View Controller. I had been having problems with the border as if I set it anywhere before viewDidAppear my method to add the border would use the wrong dimensions and display the border incorrectly. Here is the method I'm using to add a border to my UIView:
- (void)createCellBorder: (UIView *)view container:(UIView *)container {
CALayer *borderLayer = [CALayer layer];
CGRect adjustedContainer = CGRectMake(0, 0, container.frame.size.width - 20, container.frame.size.height);
CGRect borderFrame = CGRectMake(0, 0, (adjustedContainer.size.width), (view.frame.size.height));
NSLog(#"VIEW DIMENSIONS FOR %# %f, %f",view , view.frame.size.width, view.frame.size.height);
[borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
[borderLayer setFrame:borderFrame];
[borderLayer setCornerRadius:view.frame.size.height / 2];
[borderLayer setBorderWidth:1.0];
[borderLayer setBorderColor:[kTextColor2 CGColor]];
[view.layer addSublayer:borderLayer];
}
Note * To fix some bugs with a single cell having the wrong dimensions (always the final cell in the table) I am setting the width of the border layer based on the UITableView it is contained in.
Anyway I eventually found out that instead of using viewDidAppear I should be using viewDidLayoutSubviews to set my UI Geometry as at this point in time the view has calculated its dimensions. This works a treat and my cells will display with rounded borders... However there is a problem with the rendering itself.
First lets have a look at the cells being rounded from the viewDidAppear.
Everything looks fine, this is exactly how I want my cells to look (I have removed the content of them to demonstrate the borders only). Lets have a look at the code I'm using to round the cells.
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self configureCells];
}
- (void)configureCells {
[self createCellBorder:_contentCellOne container:_profileTable];
[self createCellBorder:_contentCellTwo container:_profileTable];
[self createCellBorder:_contentCellThree container:_profileTable];
[self createCellBorder:_contentCellFour container:_profileTable];
[self createCellBorder:_contentCellFive container:_profileTable];
[self createCellBorder:_contentCellSix container:_profileTable];
[self createCellBorder:_contentCellSeven container:_profileTable];
}
Now lets change where I call configureCells from and see the difference.
-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self configureCells];
}
All that has changed is where I call this method from. And in theory this should be the right place to configure my UI (and certainly more optimal than calling from viewDidAppear).
As you can see there is some quite noticeable 'distortion' around the corners of the cells. The pictures provided are from the simulator but I have tried this on a device and get the same result (maybe looks worse on my phone).
I have no idea why this is happening, and it means that whilst I have got my code out of the viewDidAppear, its just as unusable as before. I assume there will be a rendering option I can tweak in the viewDidLayoutSubViews but can't seem to find anything. All suggestions greatly appreciated!
In my opinion, you should create a subclass for UITableViewCell and configure border of cells inside layoutIfNeeded method.
I have create a demo project, you can check it TableViewCellBorder.

Objective C - OS X - Issue adding NSShadow to NSImageView

I am trying to add a shadow to a NSImageView on an MAC application.
I created a custom NSImageView class "ShadowView.h" and modified the drawRect: like so:
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowBlurRadius:5];
[shadow setShadowOffset:NSMakeSize(30.0, 3.0)];
[shadow setShadowColor:[NSColor redColor]];
[shadow set];
[self setWantsLayer:YES];
[self setShadow:shadow];
}
However nothing happens. Also, when I debug I can see the above code being called. I looked at this question from 5 years ago but it seems to not work anymore
Adding a Shadow to a NSImageView
Thank you!
When adding a shadow to a view, that view's superview also needs to have layer-backing enabled. If it doesn't, the view's shadow gets clipped at its own bounds, as seen in this sample app:
Make sure you call -setWantsLayer:YES on your view's superview (or check the "Core Animation Layer" checkbox in Interface Builder) in order to make sure the shadow is completely visible:
You should set these somewhere else like, initWithFrame: take them out of the drawRect:
[self setWantsLayer:YES];
[self setShadow:shadow];

CustomSearchBar color differs from the one in UINavigationBar

Im using:
#define colorApp [UIColor colorWithRed:254/256.f green:64/256.f blue:89/256.f alpha:1.0]
Inside the customSearchView init:
[self setBackgroundColor:colorApp];
searchBar = [[UISearchBar alloc] initWithFrame:frame];
searchBar.barTintColor = colorApp;
[self addSubview:searchBar];
Getting the next result:
I need the searchBarTint color to be the same as the navigation. Translucent doesn't seem to make the work.
I came up with the fix soon after I posted the question.
In case anyone ever faces this problem I used
[self.searchDisplayController.searchBar setBackgroundImage:[UIImage imageNamed:#"pinkBar.png"]
forBarPosition:0
barMetrics:UIBarMetricsDefault];
It seems backgroundColor and barTintColor aren't taking colors same way as the navigation for a UISearchDisplayController since iOS 7. But adding an image with that color just resolves that.
I know it's just a quick fix but it helped me and could help others as it is a minor visual issue.

Double-tap to zoom in PDF UIScrollView?

I have an "PDF Viewer" in my application. I use the CGPDFDocumentRef and CGPDFPageRef to show the PDF. To zoom in the PDF I use a UIScrollView.
I am already able to pinch-zoom in the UIScrollView but I also want to be able to double-tap to zoom.
Double tap with one finger takes you to different levels in the PDF until you hit the maximumZoomLevel and then be able to double-tap with two fingers to the minimumZoomLevel.
I haven't been able to find a solution on the Internet that shows you this in particular so I'm asking here. How could I accomplish this?
In viewDidLoad:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self.scrollView addGestureRecognizer:doubleTap];
[doubleTap release];
Method:
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer
{
if(self.scrollView.zoomScale > self.scrollView.minimumZoomScale)
[self.scrollView setZoomScale:self.scrollView.minimumZoomScale animated:YES];
else
[self.scrollView setZoomScale:self.scrollView.maximumZoomScale animated:YES];
}
I think that you can use UITapGestureRecognizer with numberOfTapsRequired property after that in handle method (which you specify when alloc/init the recognizer) and use to use – zoomToRect:animated: or – setZoomScale:animated: on the view to zoom.
Edit: keep track on current zoom level to reverse the effect.

Add a background image to TTWebController's UIToolbar

I would like to add a nice background image to the UIToolbar of a subclass of Three20's TTWebController.
Since I don't mind all UIToolbars of my app sharing the same background, I tried using UIColor colorWithPatternImage in my style sheet and that doesn't seem to work (toolbar end up solid black).
I've also tried doing something like this:
#implementation UIToolbar (MyCustomToolbarBG)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: kBackgroundImage];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
with little success..
I certainely don't want to copy and paste the entire TTWebController code just to make my own class out of it since I actually don't modify anything else, but I don't really see anything else I can do. Anyone have a suggestion?
Ok, found my way like this: I subclassed the TTWebController to subclass the loadView: method.
-(void)loadView{
[super loadView];
[_toolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed: kBackgroundImage]] autorelease] atIndex:0];
}
Better than nothing. Not extremely handy if they decide to change anything about the protected attribute _toolbar though...