简体   繁体   中英

UIView and animation doesn't appear

    UIView *timerBarView = [[UIView alloc] initWithFrame:timerRect];
    timerBarView.backgroundColor = [UIColor blueColor];
    timerBarView.alpha = 0.5;
    [theParentView addSubview:timerBarView];
    [UIView animateWithDuration:duration
                          delay:0.0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{ timerBarView.transform = CGAffineTransformMakeScale(0, 1); }
                     completion:^(BOOL fin){if(fin)[timerBarView removeFromSuperview];}];

I'm pretty sure this code worked until I updated to Xcode 6. Now the timerBar doesn't appear at all. The desired appearance is a long blue strip that shrinks horizontally to zero.

I logged the rects (immediately prior to the above code's execution) and those seem fine:

timerRect: {{10, 252}, {362, 4}}
theParentView.bounds: {{0, 0}, {382, 258}}

I even tried giving timerBarView a 100,100,200,50 rect and adding it directly to the view controller's view instead of using it as a subview. It still did not work.

So... where did my timerBar go? (;_;)

Are you testing this code in iOS 8.0+? I noticed that animations that scale to 0 do not work in ios 8 but works in ios 7.0. You can try setting a very small value instead of 0 to perform the animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM