objective-c如何幻灯片标签文本和图像相同的时间

发布时间: 2016/10/4 1:17:44
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我已经在我的应用程序中创建滑块,我想图像和标签都是幻灯片相同的时间。

此时间图像滑块工作正确但标签滑块不工作。我要一张标签文本幻灯片怎么工作。请帮助。谢谢

我的代码

- (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];


}

解决方法 1:

让作为全局变量 globalCounter,让你得到的确保测试数据

globalCounter=0;
if(nameArray.count>0){

    [self changeLable];

}

然后

-(void)changeLable{

    if(!(globalCounter<nameArray.count)){
        return;
    }


    NSLog(@"globalCounter %d",globalCounter);

    [UIView animateWithDuration:1
                          delay:0.5
                        options: UIViewAnimationOptionTransitionCrossDissolve
                     animations:^{


                     }
                     completion:^(BOOL finished) {

                         [lblTitle setText:[nameArray objectAtIndex:globalCounter]];
                         globalCounter++;

                         [self performSelector:@selector(changeLable) withObject:nil afterDelay:1];

                     }];


}
官方微信
官方QQ群
31647020