我爲我的應用程序創建了一個加載圖標。在應用程序正在加載地圖並放置標記時,我在屏幕上顯示一個正在旋轉的加載圖標。用我當前的代碼顯示加載圖標,但只有在標記全部放置在地圖上並且所有內容都已完成加載時纔會旋轉。我已經嘗試了一切,任何人都可以幫忙嗎?Objective C在定時器上加載圖標
我會附上下面的代碼,我明白這不是最好的方式來做到這一點,我打算一旦找到我在做什麼錯了,讓它在地圖加載時旋轉時,將它整理好。
謝謝。
- (void)viewDidLoad
{
[super viewDidLoad];
[email protected]"0";
rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.3
target:self
selector:@selector(rotateMove)
userInfo:nil
repeats:YES];
}
-(void)rotateMove
{
if([loading isEqual:@"1"])
{
[rotateTimer invalidate];
rotateTimer = nil;
}
if([loading isEqual:@"0"])
{
NSLog(@"move");
[UIView animateWithDuration:1.0f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[self.rotate setTransform:CGAffineTransformRotate(self.rotate.transform, M_PI_2)];
} completion:^(BOOL finished){
if (finished) {
}
}];
}
}
編輯:將地圖下面的代碼
-(void)mapload
{
[self.mapView clear];
NSString *lat = [[NSString alloc] initWithFormat:@"%g", latitude];
NSString *lng = [[NSString alloc] initWithFormat:@"%g", longitude];
NSURL *blogURL =
NSLog(@"URL = %@", blogURL);
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
if(jsonData == nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Please check your internet connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
else{
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSArray *test = [dataDictionary objectForKey:@"test"];
self.bottombutton.hidden=FALSE;
self.time.hidden=FALSE;
self.mins.hidden=FALSE;
self.rotate.hidden=TRUE;
int tes = [[test[0] valueForKey:@"time"] intValue];
}
for (int i = 0; i < [test count]; i++) {
for(NSDictionary *coordinates in test){
double la=[coordinates[@"lat"] doubleValue];
double lo=[coordinates[@"long"] doubleValue];
CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo];
CLLocationCoordinate2D coordi=loca.coordinate;
GMSMarker *marker= [[GMSMarker alloc] init];
marker=[GMSMarker markerWithPosition:coordi];
marker.snippet = coordinates[@"name"];
marker.map = self.mapView;
marker.appearAnimation = kGMSMarkerAnimationPop;
UIImage * image = [UIImage imageNamed:@"mapiconlarge"];
CGSize sacleSize = CGSizeMake(45, 45);
UIGraphicsBeginImageContextWithOptions(sacleSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, sacleSize.width, sacleSize.height)];
UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"markeradded");
marker.icon = resizedImage;
NSLog(loading);
}
}
}
}
嘗試加載定時器上viewdidappear –
相同的問題,只是試過。 –
您是否獲得@「移動」日誌輸出?如果映射init阻塞主線程,則會發生描述。這種情況的另一個症狀是,直到最後纔會看到任何「移動」記錄。 – danh