我已經在我的應用程序中創建了滑塊,我希望圖像和標籤都是同時滑動的。如何在同一時間滑動標籤文本和圖像
此時圖像滑塊正常工作,但標籤滑塊不起作用。我想要一個標籤文本幻燈片如何工作。請幫忙。謝謝
我的代碼
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_event.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *results = [json objectForKey:@"status"];
img_ary =[[results valueForKey:@"slider"]valueForKey:@"imageurl"];
NSLog(@"images fetch %@",img_ary);
des_ary =[[results valueForKey:@"slider"]valueForKey:@"title"];
NSLog(@"label text %@",des_ary);
for (NSString *line in des_ary) {
NSLog(@"%@", line);
self.label.text=line;
}
NSMutableArray *arrayImages = [[NSMutableArray alloc] init];
for (NSString *strImageUrl in img_ary) {
[arrayImages addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strImageUrl]]]];
}
self.img.animationImages = arrayImages;
_img.animationDuration=10;
_img.animationRepeatCount = 0;
[_img startAnimating];
}
標籤滑塊代碼
NSMutableArray *arraylabel = [[NSMutableArray alloc] init];
for (NSString *line in des_ary) {
NSLog(@"%@", line);
[arraylabel addObject:line];
self.label.text=arraylabel;
[self.label sizeToFit];
self.label.center = self.view.center;
self.label.textAlignment = NSTextAlignmentLeft;
[UIView animateWithDuration:0.5
animations:^{
CGRect frame = self.label.frame;
frame.origin.x = 10;
self.label.frame = frame;
} completion:nil];
}
其中是您的標籤滑塊代碼 –
但這意味着什麼**但標籤滑塊不起作用** –
請參閱http://stackoverflow.com/questions/19251506/is-there-a-way-to- animate-changing-a-uilabels-textalignment和http://stackoverflow.com/questions/11680658/how-to-animate-the-movement-of-a-uilabel –