【发布时间】:2014-04-15 06:59:18
【问题描述】:
在我的应用程序中,我使用CATransition 来滑动横幅视图。我的代码是这样的:
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
- (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++;
}
}
所以,由于计时器功能,我的主线程在动画期间卡住(或显示延迟)。我想在线程中使用这个动画,我在NSThread和NSTimer之间感到困惑,我应该怎么做?
【问题讨论】:
标签: ios nstimer synchronous catransition