ios uitextfield 和按钮转换出现/消失
Posted
技术标签:
【中文标题】ios uitextfield 和按钮转换出现/消失【英文标题】:ios uitextfield and button transition to appear/ disappear 【发布时间】:2011-07-03 01:18:27 【问题描述】:我有一个 ipad 应用程序,当用户执行一些操作时,uitextfields 和按钮会在视图中出现和消失 [工作正常]
[cancelBtn setHidden: true];
[lblOption setHidden:true];
问题是是否有某种方法可以在它们出现和消失时设置动画,例如按钮的过渡、透明 alpha,
非常感谢!
【问题讨论】:
【参考方案1】:是的。例如:
[UIView animateWithDuration:1 animations:^
cancelBtn.alpha = 0;
];
详情请见the View Programming Guide for ios。
【讨论】:
【参考方案2】: [self.view addSubview:btn5];
//
// [[txt1 layer] setBorderWidth:2.5f];
// [[txt1 layer ] setBorderColor:[UIColor blackColor].CGColor];
//
[self.view addSubview:txt1];
txt2=[[UITextField alloc] initWithFrame:CGRectMake(20,150,180 ,35)];
txt2.backgroundColor=[UIColor brownColor];
txt2.borderStyle=UITextBorderStyleRoundedRect;
txt2.textColor=[UIColor whiteColor];
txt2.adjustsFontSizeToFitWidth=YES;
txt2.backgroundColor=[UIColor clearColor];
// [[txt2 layer] setBorderWidth:2.5f];
// [[txt2 layer ] setBorderColor:[UIColor blackColor].CGColor];
//
[self.view addSubview:txt2];
txt3.userInteractionEnabled=NO;
// [btn2 setSelected:NO];
// [btn3 setSelected:NO];
// [btn4 setSelected:NO];
//
NSLog (@"Movie selected");
break;
case 2:
// [btn2 setSelected:YES];
txt3=[[UITextField alloc] initWithFrame:CGRectMake(20,110,180 ,35)];
txt3.backgroundColor=[UIColor brownColor];
txt3.borderStyle=UITextBorderStyleRoundedRect;
txt3.textColor=[UIColor whiteColor];
txt3.adjustsFontSizeToFitWidth=YES;
[self.view addSubview:txt3];
txt1.userInteractionEnabled=NO;
txt2.userInteractionEnabled=NO;
//
// [btn1 setSelected:NO];
// [btn3 setSelected:NO];
// [btn4 setSelected:NO];
NSLog (@"Play selected");
break;
case 3:
// [btn3 setSelected:YES];
//
//
//
// [btn1 setSelected:NO];
// [btn2 setSelected:NO];
// [btn4 setSelected:NO];
//
NSLog (@"Events selected");
break;
default:
// [btn4 setSelected:YES];
//
// [btn1 setSelected:NO];
// [btn2 setSelected:NO];
// [btn3 setSelected:NO];
NSLog (@"Sports selected");
break;
-(IBAction)radioButton:(id)sender
switch ([sender tag])
case 0:
[rbtn1 setSelected:YES];
[rbtn2 setSelected:NO];
NSLog(@"Movies Selected");
break;
case 1:
[rbtn2 setSelected:YES];
[rbtn1 setSelected:NO];
NSLog(@"Cinemas Selected");
// if ([rbtn1 isSelected]==YES)
// [rbtn1 setSelected:NO];
// [rbtn2 setSelected:YES];
// else
// [rbtn1 setSelected:YES];
// [rbtn2 setSelected:NO];
//
//
// break;
// case 1:
// if ([rbtn2 isSelected]==YES)
// [rbtn2 setSelected:NO];
// [rbtn2 setSelected:YES];
// else
// [rbtn2 setSelected:YES];
// [rbtn2 setSelected:NO];
//
default:
break;
【讨论】:
以上是关于ios uitextfield 和按钮转换出现/消失的主要内容,如果未能解决你的问题,请参考以下文章
iOS-基于键盘显示的UITextField高度和按钮移动的变化
如何在 IOS 的 UIAlertView 中清除 UITextfield 文本和确定按钮?
UIAlertView 中的 iOS / UITextField
[NSPlaceholderMutableString initWithString:]:转换 UITextField 后出现 nil 参数异常