-3

如何仅动画帧即。子视图而不是整个视图以及如何在该子视图中添加分段控制按钮?我希望在单击按钮时弹出子视图,但是子视图应该是半透明的,以使后面的父视图可见。

4

3 回答 3

1

首先你让你subview透明:

[subview setAlpha:0.5f];

然后在该addSubView行之前添加此代码:

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn];          // you can try carious options here
[animation setSubtype:kCATransitionFromRight];    // here too
[animation setDuration:0.3];
[animation setValue:@"Throb" forKey:@"MyAnimationType"];
[subview.layer addAnimation:animation forKey:nil];
于 2012-10-10T04:29:44.760 回答
1

如果要添加和删除它,请使用 UIView 全局,并在此视图中添加子视图

        UIView *tempView=[[UIView alloc]initWithFrame:sel.view.frame];
        /////== Add your subviews in this tempView
        tempView.transform = CGAffineTransformMakeScale(1.3, 1.3);
        tempView.alpha = 0;
        [UIView animateWithDuration:.35 animations:^{
            tempView.alpha = 0.94;
            tempView.transform = CGAffineTransformMakeScale(1, 1);
        }];
       tempView.frame=CGRectMake(0, 0, 320, 480);
        [self.view addSubview:tempView];

更新 :

首先在您的 .h 文件中获取 UIView 的对象,例如

UIView *tempView;
BOOL isOpen;

viewWillDidLoad:方法中定义这个

isOpen = NO;

并在使用此代码后

-(IBAction)btnSetting_Clicked:(id)sender
{
    if (isOpen) {
        isOpen = NO;
         [tempView removeFromSuperview];
    }
    else {
        isOpen = YES;
        tempView=[[UIView alloc]initWithFrame:self.view.frame];
        /////== Add your subviews in this tempView
        [tempView addSubview:yourSegControl];
        tempView.transform = CGAffineTransformMakeScale(1.3, 1.3);
        tempView.alpha = 0;
        [UIView animateWithDuration:.35 animations:^{
            tempView.alpha = 0.94;
            tempView.transform = CGAffineTransformMakeScale(1, 1);
        }];
        tempView.frame=CGRectMake(0, 0, 320, 480);
        [self.view addSubview:tempView];

    }
}

我希望这对你有帮助..

:)

于 2012-10-10T04:32:34.833 回答
0

您可以将子视图添加到主视图

CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *subView = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:subView];

您可以使用使其透明

[subView setAlpha:0.2];

您可以将任何 UI 控件添加到此视图。

希望这会帮助你。

于 2012-10-10T04:29:16.953 回答