내 앱에서 CATransition
을 사용하여 배너보기를 슬라이드합니다. 때문에 내 메인 스레드가 걸리면 타이머 기능으로,iOS - 애니메이션 중에 NSTimer가 앱을 중지시킵니다.
- (void)updateLabel {
BannerDC *bannerObj = [[BannerDC alloc] init];
if (count == bannerList.count){
count = 0;
} else {
bannerObj = [bannerList objectAtIndex:count];
lblFeaturedEventTitle.text = bannerObj.line1;
imgFeaturedEventImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:bannerObj.img_url]]];
// get the view that's currently showing
[self.viewBannersBackground removeFromSuperview];
[self.viewBanners addSubview:self.viewBannersBackground];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:1.0];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.viewBannersBackground layer] addAnimation:animation forKey:@"SwitchToView1"];
count++;
}
}
그래서
의 viewDidLoad()
- (void)viewDidLoad
{
[super viewDidLoad];
bannerList = [[NSMutableArray alloc] init];
bannerList = [WebFunctions fetchBannerDataHavingUrl:@"banners/event"];
NSTimer* timer = [NSTimer timerWithTimeInterval:3.0f target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
그리고 updateLabel (또는를 보여줍니다 내 코드는 다음과 같은 것입니다 지연). 스레드에서이 애니메이션을 사용하고 싶습니다. NSThread
과 NSTimer
사이에 혼란 스럽습니다. 어떻게해야합니까?
감사합니다. 내 하루를 저장했습니다. – NSIceCode
@w ... 링크를 제공해주십시오. 비동기 이미지 관리를 위해이 작업 만 수행하는 경우 imgFeaturedEventImage.image = bannerObj.img_url; NSString에서 'UIImage *'에 할당 된 호환되지 않는 포인터 유형을 표시합니다. 죄송합니다. 전 완전히 멍청한 데요. – NSIceCode
https://github.com/rs/SDWebImage는 아마도 가장 많이 사용되는 솔루션 일 것입니다. 예제 코드의 페이지를 아래로 스크롤하십시오. – Wain