gpt4 book ai didi

ios - 如何同时滑动标签文本和图像

转载 作者:行者123 更新时间:2023-12-01 20:04:13 31 4
gpt4 key购买 nike

我在我的应用程序中创建了 slider ,我想同时绘制图像和标签。
这次图像 slider 工作正常,但标签 slider 不工作。我想要一个标签文本幻灯片如何工作。请帮忙。谢谢
我的代码

- (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];
}
标签 slider 代码
 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];


}

最佳答案

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

}];


}

关于ios - 如何同时滑动标签文本和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39361685/

31 4 0