我textViews
在一个顶部有很多scrollView
,每个textView
都有一个自定义按钮,因此当用户单击textView
它时它应该展开,当它单击返回时它应该折叠到以前的位置。
我想做的是隐藏smallTextView
并显示expandedTextView
按下按钮的时间,按下按钮时我想隐藏expandedtextView
n 显示smallTextView
。但我不知道我应该怎么做。任何帮助将不胜感激。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Demo";
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
for (int i=0;i<[appDelegate.serverResponseArray count];i++)
{
self.expandTextView = [[UITextView alloc] init];
[self.expandTextView setFrame:CGRectMake(8.0f, i*50.0f+10.0f, 270.0f, 40.0f)];
[self.expandTextView setBackgroundColor:[UIColor grayColor]];
[self.expandTextView setFont:[UIFont fontWithName:@"helvetica" size:12]];
[self.expandTextView setText:@"Welcome!!!"];
[self.expandTextView setTextColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1]];
[self.expandTextView setUserInteractionEnabled:NO];
[self.scrollView addSubview:self.expandTextView];
self.expandTextView = nil;
self.expandButton = [[UIButton alloc]initWithFrame:CGRectMake(8.0f, i*50.0f+1.0f, 270.0f, 60.0f)];
[self.expandButton setBackgroundColor:[UIColor clearColor]];
[self.expandButton addTarget:self action:@selector(textButtonClicked:) forControlEvents:UIControlEventTouchDragInside];
[self.scrollView addSubview:self.expandButton];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(278.0f, i*50.0f+10.0f, 14.0f, 40.0f)];
[imageView setBackgroundColor:[UIColor grayColor]];
[imageView setImage:[UIImage imageNamed:@"arrow.png"]];
[self.scrollView addSubview:imageView];
imageView = nil;
}
float maxHeight = 0;
for(UIView *v in [self.scrollView subviews])
{
if(v.frame.origin.x + v.frame.size.height > maxHeight)
maxHeight = v.frame.origin.x + v.frame.size.height;
}
self.scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, maxHeight+2570);
}
-(void)textButtonClicked:(id)sender
{
NSLog(@"Hi");
[self.expandTextView setHidden:YES\];
NSLog(@"hey");
}
以及我如何知道按下了哪个按钮。