0
我在視圖控制器中有一個地圖視圖。它顯示預輸入座標的視圖。地圖視圖不佔用整個屏幕,我在視圖控制器上有其他項目。我想編輯地圖視圖的外觀,使邊緣彎曲而不是矩形地圖視圖。視圖控制器中的自定義視圖
我的看法Controller.m或者代碼:
#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController()
@end
@implementation ViewController
@synthesize topLayer = _topLayer;
@synthesize layerPosition = _layerPosition;
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self gotolocation];
self.topLayer.layer.shadowOffset = CGSizeMake(-1,0);
self.topLayer.layer.shadowOpacity = .9;
self.layerPosition = self.topLayer.frame.origin.x;
}
#define VIEW_HIDDEN 264
-(void) animateLayerToPoint:(CGFloat)x
{
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
CGRect frame = self.topLayer.frame;
frame.origin.x = x;
self.topLayer.frame = frame;
}
completion:^(BOOL finished){
self.layerPosition =self.topLayer.frame.origin.x;
}];
}
- (IBAction)toggleLayer:(id)sender {
if (self.layerPosition == VIEW_HIDDEN) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint:VIEW_HIDDEN];
}
}
- (IBAction)panLayer:(UIPanGestureRecognizer*)pan {
if (pan.state == UIGestureRecognizerStateChanged) {
CGPoint point = [pan translationInView:self.topLayer];
CGRect frame = self.topLayer.frame;
frame.origin.x = self.layerPosition + point.x;
if (frame.origin.x < 0) frame.origin.x = 0;
self.topLayer.frame = frame;
}
if (pan.state == UIGestureRecognizerStateEnded) {
if (self.topLayer.frame.origin.x <= 160) {
[self animateLayerToPoint:0];
} else {
[self animateLayerToPoint: VIEW_HIDDEN];
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) gotolocation {
MKCoordinateRegion newRegion;
newRegion.center.latitude = 28.533569;
newRegion.center.longitude = 77.144776;
newRegion.span.latitudeDelta = 0.001657;
newRegion.span.longitudeDelta = 0.00284;
CLLocationCoordinate2D coordinate;
coordinate.latitude = 28.533569; coordinate.longitude = 77.144776;
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:coordinate];
[annotation setTitle:@"Vasant Valley School"];
[self.mapView addAnnotation:annotation];
[self.mapView setRegion:newRegion animated:YES];
}
@end
我添加它的viewDidLoad,但它沒有工作,我應該張貼我的代碼? –
是的,這可能會幫助 – Rob
我發佈的代碼.... –