我有一個大小爲(320,182)的mapView。一旦按下了UIBarButtonItem
,我想顯示這個mapView從屏幕頂部向下滑動。爲了達到這個目的,我編寫了這樣的代碼。顯示從頂部向下滑動的半屏視圖
UIBarButtonItem *mapButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"map_1.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(showMap:)
];
self.navigationItem.rightBarButtonItem = mapButton;
-(void)showMap:(id)sender{
self._mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,-182,320,182)];
[self.scrollView addSubview:self._mapView];
//show view
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.0];
CGRect rect = [self._mapView frame];
rect.origin.y = 0;
[self._mapView setFrame:rect];
[UIView commitAnimations];
}
這將顯示從屏幕頂部向下滑動的地圖視圖。但是,如何在第二次按UIBarButtonItem
時使mapView關閉?此外,我還想在mapView外部點擊時關閉mapView。
它的工作!的確非常感謝你的幫助。 – kenken