【发布时间】:2011-10-31 13:02:22
【问题描述】:
我有一个自定义 UIView,其中包含 UIImageView、UILabel 和 UIButton 类型的嵌套视图。视图是用这样的代码创建的:
- (void)setupView
{
popupView = [[UIView alloc] initWithFrame:CGRectMake(-116, -61, 247, 59)];
popupView.autoresizingMask = 63;
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bubble.png"]];
bgImageView.autoresizingMask = 63;
[popupView addSubview:bgImageView];
[bgImageView release];
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 180, 20)];
textLabel.autoresizingMask = 63;
textLabel.font = [UIFont fontWithName:@"DefaultNormal" size:16];
textLabel.text = @"DYNAMIC TEXT";
[popupView addSubview:textLabel];
popupButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
[rightAccessoryButton setImage:[UIImage imageNamed:@"btn-tick.png"] forState:UIControlStateNormal];
popupButton.frame = CGRectMake(208, 8, 32, 32);
popupButton.autoresizingMask = 63;
[popupView addSubview:rightAccessoryButton];
}
我已将他们所有的autoresizingMasks 设置为 63,这基本上是所有内容都处于 ON 位置(除了将所有常量放在一大行代码中之外,我不知道更好的方法!)。然后当他们需要为弹出窗口设置动画时,我会这样做:
- (void)animateIn
{
float pw = 247;
float ph = 59;
// set the view's initial position
popupView.frame = CGRectMake(-pw*0.005+8, -ph*0.01-2, pw*0.01, ph*0.01);
[self addSubview:popupView];
[UIView animateWithDuration:0.12 delay:0.0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionLayoutSubviews animations:^(void) {
popupView.frame = CGRectMake(-pw*0.55+8, -ph*1.1-2, pw*1.1, ph*1.1);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionLayoutSubviews animations:^(void) {
popupView.frame = CGRectMake(-pw*0.475+8, -ph*0.95-2, pw*0.95, ph*0.95);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.075 delay:0.0 options:UIViewAnimationOptionLayoutSubviews animations:^(void) {
popupView.frame = CGRectMake(-round(pw/2-8), -ph-2, pw, ph);
} completion:nil];
}];
}];
}
看起来有点复杂的动画,但实际上这是与地图视图标注视图动画相同的动画。
唯一的问题是,它在 iOS 5 设备上完美运行,但在 iOS 4 设备上,一切都错了!标签根本不显示,按钮出现然后飞走,缩小到右上角,背景图像拉伸到错误的大小和错误的位置。
还有其他人对 iOS 4 中的动画有任何问题吗?我是否必须采取与目前不同的方式才能使其发挥作用?
【问题讨论】:
标签: uiview ios4 ios5 objective-c-blocks uiviewanimation