如何仅为框架设置动画,即。子视图而不是整个视图以及如何在该子视图中添加分段控制按钮?我希望在单击按钮时弹出子视图,但子视图应该是半透明的,以便后面的父视图可见。
答案 0 :(得分: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];
答案 1 :(得分: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];
}
}
我希望这可以帮到你..
:)
答案 2 :(得分: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控件。
希望这会帮助你。