开发者

play animation regardless of any screen iphone

i have some animation to be played at some point in time. that time is decided by some thread running in the backgroud. now i want to play the animation regardless of which screen the user is on. here is screen hierarchy.

login-->homescreen(thread starts running from viewdidload).

from home screen the user may navigate to any other screen and i want the animation to be played. right now i have the animationviewcontrller a membervariable in the homescreen and i am calling it by allocing and initing and pushing and popping when animation is done. and it works only 10% of the time. i have tried performselectoronmainthread and its still the same.

How do i redesign my code such that 开发者_如何学运维is plays on anyscreen.

here is my code for my thread.

[self startTimerThread];   // in viewdidload

-(void)startTimerThread
{
    homescreenthread = [[NSThread alloc] initWithTarget:self selector:@selector(setupTimerThread) object:nil];
    [homescreenthread start];
}
-(void)setupTimerThread
{
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    NSTimer* timer = [NSTimer timerWithTimeInterval:5
                                             target:self
                                           selector:@selector(findnewmessages)
                                           userInfo:nil
                                            repeats:YES];
    NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSRunLoopCommonModes];
    //[runLoop addTimer:timer forModes:NSRunLoopCommonModes];
    [runLoop run];
    [pool release];
}

-(void)findnewmessages
{//finding message from server here. i am using the following request
    NSData *serverReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
        NSString *replyString = [[NSString alloc] initWithBytes:[serverReply bytes] length:[serverReply length] encoding: NSASCIIStringEncoding];

//i have omitted lot of other code. }


use the delegate of the app to display the animation view.

id appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.m_window addSubview:viewController.view];

Also if you are tying to draw anything on the screen it should be done on main thread.

Please let me know if it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜