how to add delay to mkannotation pin drop - ios6

In my map view I set the map to open, then with a delay of 2 seconds the map zooms in to show my mkannotation, what I have been trying to do is to animate the pin dropping once the view is fully zoomed in, but haven't been able to achieve this.
So basically I want to add a delay to the annotation+pin being dropped at my location.
How do I do this?
Code what I have in place currently in ViewDidLoad, the code for the mkannotation is in void - showDetails:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 54.5;
region.center.longitude = -3.5;
region.span.longitudeDelta = 10.0f;
region.span.latitudeDelta = 10.0f;
[mapView setRegion:region animated:NO];
[self performSelector:#selector(zoomInToMyLocation)
withObject:nil
afterDelay:2]; //will zoom in after 2 seconds
}
-(void)zoomInToMyLocation
{
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 51.502729 ;
region.center.longitude = -0.071948;
region.span.longitudeDelta = 0.19f;
region.span.latitudeDelta = 0.19f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = #"Design Museum";
ann.subtitle = #"Camberwell, London";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}

If you set the delegate before you set the region your delegate will receive a call to mapView:regionDidChangeAnimated. That is called many times while scrolling so what you could do is check the map's current center point and when it is close enough to your target center point you add the annotation.
- (void)viewDidLoad
{
[super viewDidLoad];
[mapView setDelegate:self];
............
haveAddedPin = false;
}
-(void)zoomInToMyLocation
{
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 51.502729 ;
region.center.longitude = -0.071948;
region.span.longitudeDelta = 0.19f;
region.span.latitudeDelta = 0.19f;
[mapView setRegion:region animated:YES];
}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(Boolean) animated)
{
if (haveAddedPin == false && mapView.center == the coordinates of the target you are zooming to)
{
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = #"Design Museum";
ann.subtitle = #"Camberwell, London";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
haveAddedPin = true;
}
}

Related

SceneKit: how to create chessboard pattern for SCNFloor from image?

The goal is to create an infinite chessboard pattern.
Using a SCNFloor and the attached image, we produce something close but not quite like a chessboard. Some black squares merge where they shouldn't.
We tried different values for Scale, WrapS, WrapT, Min filter, Map filter, and Mip filter. The screenshot shows the current values.
Is the underlying image not correct, or what setting do we need to change for the SCNFloor?
Repeated image:
Result:
#import "GameViewController.h"
#interface GameViewController ()
#property (nonatomic) CGFloat chessBoardWidth;
#property (nonatomic) CGFloat chessBoardDepth;
#property (nonatomic) CGFloat tileWidth;
#property (nonatomic) CGFloat tileDepth;
#property (nonatomic, getter=isOdd) BOOL odd;
#end
#implementation GameViewController
-(instancetype)init {
self = [super init];
if(self) {
self.chessBoardWidth = 10.0f;
self.chessBoardDepth = 10.0f;
self.tileWidth = 1.0f;
self.tileDepth = 1.0f;
}
return self;
}
-(void)awakeFromNib
{
[super awakeFromNib];
// create a new scene
SCNScene *scene = [SCNScene sceneNamed:#"art.scnassets/chessboard.scn"];
// create and add a camera to the scene
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
[scene.rootNode addChildNode:cameraNode];
// place the camera
cameraNode.position = SCNVector3Make(0, 0, 150);
// create and add a light to the scene
SCNNode *lightNode = [SCNNode node];
lightNode.light = [SCNLight light];
lightNode.light.type = SCNLightTypeOmni;
lightNode.position = SCNVector3Make(0, 10, 10);
[scene.rootNode addChildNode:lightNode];
// create and add an ambient light to the scene
SCNNode *ambientLightNode = [SCNNode node];
ambientLightNode.light = [SCNLight light];
ambientLightNode.light.type = SCNLightTypeAmbient;
ambientLightNode.light.color = [NSColor darkGrayColor];
[scene.rootNode addChildNode:ambientLightNode];
// Material
SCNMaterial *blackMaterial = [SCNMaterial material];
blackMaterial.diffuse.contents = [NSColor blackColor];
SCNMaterial *whiteMaterial = [SCNMaterial material];
whiteMaterial.diffuse.contents = [NSColor whiteColor];
// Geometry
SCNPlane *blackTile = [[SCNPlane alloc] init];
blackTile.firstMaterial = blackMaterial;
SCNPlane *whiteTile = [[SCNPlane alloc] init];
whiteTile.firstMaterial = whiteMaterial;
// Parent node
SCNNode *parentNode = [[SCNNode alloc] init];
[scene.rootNode addChildNode:parentNode];
self.odd = YES;
for (uint x=0; x < self.chessBoardWidth; x++) {
for (uint z=0; z < self.chessBoardDepth; z++) {
// Add tile
SCNNode *tileNode = [[SCNNode alloc] init];
if(self.isOdd) {
tileNode.geometry = blackTile;
} else {
tileNode.geometry = whiteTile;
}
[parentNode addChildNode:tileNode];
// Position tile
tileNode.position = SCNVector3Make(self.tileWidth * x, 0, self.tileDepth * z);
// Alternate
if(self.isOdd) {
self.odd = NO;
} else {
self.odd = YES;
}
}
}
// set the scene to the view
self.gameView.scene = scene;
// allows the user to manipulate the camera
self.gameView.allowsCameraControl = YES;
// show statistics such as fps and timing information
self.gameView.showsStatistics = YES;
// configure the view
self.gameView.backgroundColor = [NSColor grayColor];
}
#end

UITapGestureRecognizer work by default on UISwipeGestureRecognizer

In my code by default work UITapGesture how to remove this
NSString *dirString;
host is class object
-(Void) handleSwipeEvent : (UISwipeGestureRecognizer *) recognizer {
//NSString *swipeDirection = NULL;
//CGPoint location = [recognizer locationInView:self];
dirString = NULL;
UITapGestureRecognizer *tap=nil;
tap.enabled=NO;
if ([recognizer direction] == UISwipeGestureRecognizerDirectionLeft) {
dirString = kCATransitionFromRight;
}
if ([recognizer direction] == UISwipeGestureRecognizerDirectionRight)
{
dirString = kCATransitionFromLeft;
}
if (dirString) [host swipeTo:dirString];
}
-(void)createSwipeGestureRecognizer:(UIView *)view direction: (UISwipeGestureRecognizerDirection)direction
{
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeEvent:)];
[view addGestureRecognizer:recognizer];
[recognizer setDirection:direction];
[self setSwipeRecognizer:recognizer];
[recognizer release];
}
- (void) setHost: (FlashCardViewController *) aHost {
host = aHost;
[self createSwipeGestureRecognizer:self direction:UISwipeGestureRecognizerDirectionLeft];
[self createSwipeGestureRecognizer:self direction:UISwipeGestureRecognizerDirectionRight];
}
On the view i have to touch then load next contant.
How can i disable tap event

drawing rounded rect on imageContext using UIBeizerpath not working

I had a requirement to draw a rounded rect while user touch is moving on iPad.
Here is my code it is showing black color rounded rect while touch moving and selected color when touch is ended. Can any one please tell me the reason?
- (void)drawRect:(CGRect)rect
{
[path setLineWidth:lineSize];
[selectedColor setStroke];
[drawImage drawInRect:rect]; // (3)
[path fill];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
startPoint=p;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
float x=startPoint.x;
float y=startPoint.y;
float z=p.x-startPoint.x;
float a=p.y-startPoint.y;
if (z<0 && a<0) {
x=p.x;
y=p.y;
z=startPoint.x-p.x;
a=startPoint.y-p.y;
}
else if (a<0)
{
x=startPoint.x;
y=startPoint.y;
z=p.x-startPoint.x;
a=startPoint.y-p.y;
}
else if(z<0)
{
x=startPoint.x;
y=startPoint.y;
z=startPoint.x-p.x;
a=p.y-startPoint.y;
}
path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x,y,z,a) cornerRadius:10.0];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[self drawBitmap];
[self setNeedsDisplay];
}
- (void)drawBitmap // (3)
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);
[selectedColor setStroke];
if (!drawImage) // first draw; paint background white by ...
{
UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds]; // enclosing bitmap by a rectangle defined by another UIBezierPath object
[[UIColor whiteColor] setFill];
[rectpath fill]; // filling it with white
}
[drawImage drawAtPoint:CGPointZero];
[selectedColor setFill];
[path fill];
drawImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
Edit your initWithFrame method to make background of the UIView white.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
}
return self;
}

Unexpected '#' in xcode after upgrade of xcode

Can someone help me out with why this error showed up after I upgraded to the newest version of xcode? The app was working fine prior to this, but this syntax error prevents compiling now. I am getting the error at
#pragma mark -#property (nonatomic, k Constants,
and also I get a missing #end error.
Sorry for posting the entire page, but I wanted to make sure I provided enough to get assistance.
#import "MBProgressHUD.h"
#interface MBProgressHUD ()
(void)hideUsingAnimation:(BOOL)animated;
(void)showUsingAnimation:(BOOL)animated;
(void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context;
(void)done;
(void)updateLabelText:(NSString *)newText;
(void)updateDetailsLabelText:(NSString *)newText;
(void)updateProgress;
(void)updateIndicators;
(void)handleGraceTimer:(NSTimer *)theTimer;
(void)handleMinShowTimer:(NSTimer *)theTimer;
#property (retain) UIView *indicator;
#property (assign) float width;
#property (assign) float height;
#property (retain) NSTimer *graceTimer;
#property (retain) NSTimer *minShowTimer;
#property (retain) NSDate *showStarted;
#end
#implementation MBProgressHUD
#pragma mark -
#pragma mark Accessors
#synthesize mode;
#synthesize delegate;
#synthesize labelText;
#synthesize detailsLabelText;
#synthesize opacity;
#synthesize labelFont;
#synthesize detailsLabelFont;
#synthesize progress;
#synthesize indicator;
#synthesize width;
#synthesize height;
#synthesize xOffset;
#synthesize yOffset;
#synthesize graceTime;
#synthesize minShowTime;
#synthesize graceTimer;
#synthesize minShowTimer;
#synthesize taskInProgress;
#synthesize showStarted;
(void)setMode:(MBProgressHUDMode)newMode {
if (mode && (mode == newMode)) {
return;
}
mode = newMode;
[self performSelectorOnMainThread:#selector(updateIndicators) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setLabelText:(NSString *)newText {
[self performSelectorOnMainThread:#selector(updateLabelText:) withObject:newText waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setDetailsLabelText:(NSString *)newText {
[self performSelectorOnMainThread:#selector(updateDetailsLabelText:) withObject:newText waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
(void)setProgress:(float)newProgress {
progress = newProgress;
if (mode == MBProgressHUDModeDeterminate) {
[self performSelectorOnMainThread:#selector(updateProgress) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:#selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
}
}
#pragma mark -
#pragma mark Accessor helpers
(void)updateLabelText:(NSString *)newText {
if (labelText != newText) {
[labelText release];
labelText = [newText copy];
}
}
(void)updateDetailsLabelText:(NSString *)newText {
if (detailsLabelText != newText) {
[detailsLabelText release];
detailsLabelText = [newText copy];
}
}
(void)updateProgress {
[(MBRoundProgressView *)indicator setProgress:progress];
}
(void)updateIndicators {
if (indicator) {
[indicator removeFromSuperview];
}
self.indicator = nil;
if (mode == MBProgressHUDModeDeterminate) {
self.indicator = [[MBRoundProgressView alloc] initWithDefaultSize];
}
else {
self.indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[(UIActivityIndicatorView *)indicator startAnimating];
}
[self addSubview:indicator];
}
**#pragma mark -
#property (nonatomic, k Constants**
#define MARGIN 20.0
#define PADDING 4.0
#define LABELFONTSIZE 22.0
#define LABELDETAILSFONTSIZE 16.0
#define PI 3.14159265358979323846
#pragma mark -
#pragma mark Lifecycle methods
(id)initWithWindow:(UIWindow *)window {
#property (nonatomic, nonatomic, nonatomic, [self initWithView:window];
}
(id)initWithView:(UIView *)view {
initializer above)
if (!view) {
#property (nonatomic, ion raise:#"MBProgressHUDViewIsNillException"
format:#"The view used in the MBProgressHUD initializer is nil."];
}
return [self initWithFrame:view.bounds];
}
(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.mode = MBProgressHUDModeIndeterminate;
self.labelText = nil;
self.detailsLabelText = nil;
self.opacity = 0.9;
self.labelFont = [UIFont boldSystemFontOfSize:LABELFONTSIZE];
self.detailsLabelFont = [UIFont boldSystemFontOfSize:LABELDETAILSFONTSIZE];
self.xOffset = 0.0;
self.yOffset = 0.0;
self.graceTime = 0.0;
self.minShowTime = 0.0;
self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.alpha = 0.0;
label = [[UILabel alloc] initWithFrame:self.bounds];
detailsLabel = [[UILabel alloc] initWithFrame:self.bounds];
taskInProgress = NO;
}
return self;
}
(void)dealloc {
[indicator release];
[label release];
[detailsLabel release];
[labelText release];
[detailsLabelText release];
[graceTimer release];
[minShowTimer release];
[showStarted release];
[super dealloc];
}
#pragma mark -
#pragma mark Layout
(void)layoutSubviews {
CGRect frame = self.bounds;
#property (nonatomic, indFrame = indicator.bounds;
self.width = indFrame.size.width + 2 * MARGIN;
self.height = indFrame.size.height + 2 * MARGIN;
indFrame.origin.x = floor((frame.size.width - indFrame.size.width) / 2) + self.xOffset;
indFrame.origin.y = floor((frame.size.height - indFrame.size.height) / 2) + self.yOffset;
indicator.frame = indFrame;
if (nil != self.labelText) {
CGSize dims = [self.labelText sizeWithFont:self.labelFont];
clip the label width
float lHeight = dims.height;
float lWidth;
if (dims.width <= (frame.size.width - 2 * MARGIN)) {
lWidth = dims.width;
}
else {
lWidth = frame.size.width - 4 * MARGIN;
}
label.font = self.labelFont;
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentCenter;
label.opaque = NO;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = self.labelText;
if (self.width < (lWidth + 2 * MARGIN)) {
self.width = lWidth + 2 * MARGIN;
}
self.height = self.height + lHeight + PADDING;
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
indicator.frame = indFrame;
// Set the label position and dimensions
CGRect lFrame = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
floor(indFrame.origin.y + indFrame.size.height + PADDING),
lWidth, lHeight);
label.frame = lFrame;
[self addSubview:label];
// Add details label delatils text was set
if (nil != self.detailsLabelText) {
// Get size of label text
dims = [self.detailsLabelText sizeWithFont:self.detailsLabelFont];
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
lHeight = dims.height;
if (dims.width <= (frame.size.width - 2 * MARGIN)) {
lWidth = dims.width;
}
else {
lWidth = frame.size.width - 4 * MARGIN;
}
// Set label properties
detailsLabel.font = self.detailsLabelFont;
detailsLabel.adjustsFontSizeToFitWidth = NO;
detailsLabel.textAlignment = UITextAlignmentCenter;
detailsLabel.opaque = NO;
detailsLabel.backgroundColor = [UIColor clearColor];
detailsLabel.textColor = [UIColor whiteColor];
detailsLabel.text = self.detailsLabelText;
// Update HUD size
if (self.width < lWidth) {
self.width = lWidth + 2 * MARGIN;
}
self.height = self.height + lHeight + PADDING;
// Move indicator to make room for the new label
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
indicator.frame = indFrame;
// Move first label to make room for the new label
lFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
label.frame = lFrame;
// Set label position and dimensions
CGRect lFrameD = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
lFrame.origin.y + lFrame.size.height + PADDING, lWidth, lHeight);
detailsLabel.frame = lFrameD;
[self addSubview:detailsLabel];
}
}
}
#pragma mark -
#pragma mark Showing and execution
- (void)show:(BOOL)animated {
useAnimation = animated;
// If the grace time is set postpone the HUD display
if (self.graceTime > 0.0) {
self.graceTimer = [NSTimer scheduledTimerWithTimeInterval:self.graceTime
target:self
selector:#selector(handleGraceTimer:)
userInfo:nil
repeats:NO];
}
// ... otherwise show the HUD imediately
else {
[self setNeedsDisplay];
[self showUsingAnimation:useAnimation];
}
}
- (void)hide:(BOOL)animated {
useAnimation = animated;
// If the minShow time is set, calculate how long the hud was shown,
// and pospone the hiding operation if necessary
if (self.minShowTime > 0.0 && showStarted) {
NSTimeInterval interv = [[NSDate date] timeIntervalSinceDate:showStarted];
if (interv < self.minShowTime) {
self.minShowTimer = [NSTimer scheduledTimerWithTimeInterval:(self.minShowTime - interv)
target:self
selector:#selector(handleMinShowTimer:)
userInfo:nil
repeats:NO];
return;
}
}
// ... otherwise hide the HUD immediately
[self hideUsingAnimation:useAnimation];
}
- (void)handleGraceTimer:(NSTimer *)theTimer {
// Show the HUD only if the task is still running
if (taskInProgress) {
[self setNeedsDisplay];
[self showUsingAnimation:useAnimation];
}
}
- (void)handleMinShowTimer:(NSTimer *)theTimer {
[self hideUsingAnimation:useAnimation];
}
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
methodForExecution = method;
targetForExecution = [target retain];
objectForExecution = [object retain];
// Launch execution in new thread
taskInProgress = YES;
[NSThread detachNewThreadSelector:#selector(launchExecution) toTarget:self withObject:nil];
// Show HUD view
[self show:animated];
}
- (void)launchExecution {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Start executing the requested task
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
// Task completed, update view in main thread (note: view operations should
// be done only in the main thread)
[self performSelectorOnMainThread:#selector(cleanUp) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context {
[self done];
}
- (void)done {
isFinished = YES;
// If delegate was set make the callback
self.alpha = 0.0;
if(delegate != nil && [delegate conformsToProtocol:#protocol(MBProgressHUDDelegate)]) {
if([delegate respondsToSelector:#selector(hudWasHidden)]) {
[delegate performSelector:#selector(hudWasHidden)];
}
}
}
- (void)cleanUp {
taskInProgress = NO;
self.indicator = nil;
[targetForExecution release];
[objectForExecution release];
[self hide:useAnimation];
}
#pragma mark -
#pragma mark Fade in and Fade out
- (void)showUsingAnimation:(BOOL)animated {
self.showStarted = [NSDate date];
// Fade in
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.40];
self.alpha = 1.0;
[UIView commitAnimations];
}
else {
self.alpha = 1.0;
}
}
- (void)hideUsingAnimation:(BOOL)animated {
// Fade out
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.40];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished: finished: context:)];
// 0.02 prevents the hud from passing through touches during the animation the hud will get completely hidden
// in the done method
self.alpha = 0.02;
[UIView commitAnimations];
}
else {
self.alpha = 0.0;
[self done];
}
}
#pragma mark BG Drawing
- (void)drawRect:(CGRect)rect {
// Center HUD
CGRect allRect = self.bounds;
// Draw rounded HUD bacgroud rect
CGRect boxRect = CGRectMake(((allRect.size.width - self.width) / 2) + self.xOffset,
((allRect.size.height - self.height) / 2) + self.yOffset, self.width, self.height);
CGContextRef ctxt = UIGraphicsGetCurrentContext();
[self fillRoundedRect:boxRect inContext:ctxt];
}
- (void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context {
float radius = 10.0f;
CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 0.0, self.opacity);
CGContextMoveToPoint(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect));
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMinY(rect) + radius, radius, 3 * M_PI / 2, 0, 0);
CGContextAddArc(context, CGRectGetMaxX(rect) - radius, CGRectGetMaxY(rect) - radius, radius, 0, M_PI / 2, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMaxY(rect) - radius, radius, M_PI / 2, M_PI, 0);
CGContextAddArc(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect) + radius, radius, M_PI, 3 * M_PI / 2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
#end
#implementation MBRoundProgressView
- (id)initWithDefaultSize {
return [super initWithFrame:CGRectMake(0.0f, 0.0f, 37.0f, 37.0f)];
}
- (void)drawRect:(CGRect)rect {
CGRect allRect = self.bounds;
CGRect circleRect = CGRectMake(allRect.origin.x + 2, allRect.origin.y + 2, allRect.size.width - 4,
allRect.size.height - 4);
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); // white
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.1); // translucent white
CGContextSetLineWidth(context, 2.0);
CGContextFillEllipseInRect(context, circleRect);
CGContextStrokeEllipseInRect(context, circleRect);
// Draw progress
float x = (allRect.size.width / 2);
float y = (allRect.size.height / 2);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); // white
CGContextMoveToPoint(context, x, y);
CGContextAddArc(context, x, y, (allRect.size.width - 4) / 2, -(PI / 2), (self.progress * 2 * PI) - PI / 2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
#end
The line throwing the error makes no sense.
#pragma mark -
#property (nonatomic, k Constants
the #pragma mark - puts a line in the drop down list but what is the next line supposed to do?
if you are declaring a property, then you haven't closed the bracket after nonatomic, but when what is k Constants supposed to be. Are you sure you didn't change the file?

by Adding Polyline(path) on MKMapview crashing the app in ios6

I have a requirement to adding a path in my MKMapview between two annotation pin. There is no issue with ios 5 or older but when i try to run app in ios 6 app is surprisingly quit. below is my code. If there is any correction in my code then please suggest me.
1.So my question is suggest the best way how to decrees memory in my following code so that i can solve crash in my Application.
- (void)viewDidLoad
{
NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoints:pathArray mapView:_mapView];
[_mapView addAnnotation:annotation];
[annotation release];
[pathArray removeAllObjects];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(#"%s",__FUNCTION__);
if ([annotation isKindOfClass:[NVPolylineAnnotation class]])
{
NSLog(#"=========ANOTATION=========NVPolylineAnnotationView START");
//ann=[ann initWithAnnotation:annotation mapView:_mapView];
NVPolylineAnnotationView *ann=[[NVPolylineAnnotationView alloc] init];
return [[ann initWithAnnotation:annotation mapView:_mapView] autorelease];//[[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation mapView:_mapView] autorelease];
}
else if([annotation isKindOfClass:[MapViewAnnotation class]])
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pointers"] ;
// annView.rightCalloutAccessoryView = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
annView.animatesDrop=NO;
annView.canShowCallout = TRUE;
return [annView autorelease];
}
else if([annotation isKindOfClass:[PlacePin class]])
{
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
}
else {
[mapView.userLocation setTitle:#"I am here"];
}
return pinView;
}
}
return nil;
}
- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(#"%s",__FUNCTION__);
// fixes that some marker are behind the polyline
for (int i=0; i<[views count]; i++)
{
MKAnnotationView *view = [views objectAtIndex:i];
if ([view isKindOfClass:[NVPolylineAnnotationView class]])
{
[[view superview] sendSubviewToBack:view];
/* In iOS version above 4.0 we need to update the polyline view after it
has been added to the mapview and it ready to be displayed. */
NSString *reqSysVer = #"4.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[self updatePolylineAnnotationView];
}
}
}
NSLog(#"----------didAddAnnotationViews");
}
- (void)updatePolylineAnnotationView
{
NSLog(#"%s",__FUNCTION__);
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
[mapView selectAnnotation:mp animated:NO];
*/
for (NSObject *a in [_mapView annotations])
{
if ([a isKindOfClass:[NVPolylineAnnotation class]])
{
NVPolylineAnnotation *polyline = (NVPolylineAnnotation *)a;
NSObject *pv = (NSObject *)[_mapView viewForAnnotation:polyline];
if ([pv isKindOfClass:[NVPolylineAnnotationView class]])
{
NVPolylineAnnotationView *polylineView =
(NVPolylineAnnotationView *)[_mapView viewForAnnotation:polyline];
[polylineView regionChanged];
}
}
}
}

Resources