IanMK2 Blog

현재 위치와 어느한지점을 지도에 뿌리기위해 맵뷰를 쓸일이 생겼다.

사전작업은 다음과 같다.
프레임워크에서 CoreLocation.framework를 추가
헤더는 MapKit/MapKit.h를 추가
일단 원하는 위치에 핀을 박기위한 클래스
///////////////////PlaceMark.h//////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface PlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSString *title;
@property (nonatomic, assign) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end


//////////////////PlaceMark.m/////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface PlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSString *title;
@property (nonatomic, assign) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end



실제 사용소스시
        MKMapView *gmap = [[MKMapView alloc] initWithFrame:self.view.bounds];
gmap.showsUserLocation = TRUE; //자기위치 표시
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.005;//표시되는 영역의 설정 수치가 작을수록 더 확대된다.
span.longitudeDelta= 0.005;
CLLocationCoordinate2D location = gmap.userLocation.coordinate;
location.latitude=[[storedata objectForKey:@"latitude"] floatValue];//GPS좌표경위도설정
location.longitude=[[storedata objectForKey:@"longitude"] floatValue];
region.span = span;
region.center = location;
[gmap setRegion:region animated:TRUE];
[gmap regionThatFits:region];
PlaceMark *placemark = [[PlaceMark alloc] initWithCoordinate:location]; //핀박을위치설정
placemark.title = @"Title"
placemark.subtitle = @"SubTitle";

[gmap addAnnotation:placemark];  //핀을 박아넣는다.
[self.view addSubview:gmap]; //뷰에 추가

[placemark release];
[gmap release];


Posted by IanMK2
NSString * pStr = [[NSString stringWithstring:@"tel:전화번호] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:pStr]];

전화걸때 쓰면 된다. (간단간단)
Posted by IanMK2
-(void)textViewDidBeginEditing:(UITextView *)textView{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"완료"  style:UIBarButtonSystemItemSave target:self action:@selector(done)];

[self.navigationItem setRightBarButtonItem:doneButton];
[doneButton release];
[scrollview setContentOffset:CGPointMake(0, 190) animated:YES];
}
-(void)done{
[self.navigationItem setRightBarButtonItem:nil];
[self.textview resignFirstResponder];
[scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

텍스트뷰에 멀티라인을 입력한 후 편집모드를 나오기 위해 네비게이션에 완료버튼을 추가하고
버튼을 누르면 키보드를 집어넣는 기능이다. 덤으로 스크롤뷰도 스크롤한다.
Posted by IanMK2

선언은

NSCalendar *calendar = [NSCalendar currentCalendar];

unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDateComponents *c = [calendar components:unitFlags fromDate:[NSDate date]]; 

 

나중에 release하는 것을 잊지말자


[c year]    

[c month] 

[c day]    

[c hour]   

[c minute]

[c second]

Posted by IanMK2
앱을 만들던도중 특정영역의 터치를 검사해서 이벤트를 발생시킬 일이 생겼다.
이리저리 찾아본결과
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

CGPoint currentPos = [[touches anyObject] locationInView:self];

if(CGRectContainsPoint(CGRectMake(10,10,100, 100 ),currentPos))
작업실행;
}

위와같이 뷰클래스 소스에 추가해주면된다.
위 메서드 말고도뒤가 ended등으로 끝나는 시리즈가 있다.

*주의사항 : 스크롤뷰는 위의 함수가 호출이 안된다. 그래서 스크롤뷰안에 다시 뷰를 생성하고 그 뷰안에서 저 함수를 추가하고 처리해야한다.
Posted by IanMK2