在scrollview中隐藏textview

时间:2011-03-23 11:49:46

标签: iphone animation uiscrollview uitextview

我正在开发一个应用程序,其中我在scrollview中添加了textview和一个按钮。 滚动视图是根据数据库的数据使用数组动态生成的。 现在我要做的是文本视图应隐藏在我在滚动视图中添加的按钮单击。

代码.........

- 加载滚动视图.....

- (void)loadScrollView {

cxs=0;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dreambuilder.sqlite"];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) 
{
    const char *sql;

    sql = "select  dname, dream from dream order by dorder";
    //btnNextDream.enabled = FALSE;
    sqlite3_stmt *statement;
    statement = nil;
    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) 
    {

        sqlite3_bind_int(statement, 1, objAppdelDreamDetail.intEditDream );
        while (sqlite3_step(statement) == SQLITE_ROW) 
        {

            btnItem = [[UIButton alloc]init];
            btnItem.backgroundColor=[UIColor clearColor];
            txtViewDescription = [[UITextView alloc]init];
            CGRect rect;  
            rect.origin.x = ((myScroll.frame.size.width - 320) /2) + cxs ;
            rect.origin.y = 0;
            rect.size.height = 460;
            rect.size.width = 320;
            [btnItem addTarget:self action:@selector(actionShowDreamImage:) forControlEvents:UIControlEventTouchUpInside];
            btnItem.frame = rect;
            [btnItem setImage:[UIImage imageWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]]] forState:UIControlStateNormal]; 
            NSString *s=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] ;
            for(int i=0;i<[arrDream count];i++)
            {
                txtViewDescription.tag=i;

            if ([s isEqual:@""]) {
                    txtViewDescription.frame=CGRectMake(rect.origin.x+15, 60, 300, 40);
                }else {
                    CGSize textViewSize = [s sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(300, 460) lineBreakMode:UILineBreakModeWordWrap];
                    txtViewDescription.frame=CGRectMake(rect.origin.x+15, 60, 300, textViewSize.height+10);
                    txtViewDescription.text=s;
                }
                txtViewDescription.alpha = 0.5; 
                txtViewDescription.layer.cornerRadius=10.0;
                txtViewDescription.font=[UIFont fontWithName:@"Helvetica" size:18];
                txtViewDescription.backgroundColor=[UIColor blackColor];
                txtViewDescription.textColor=[UIColor whiteColor];
                txtViewDescription.editable = NO;
                txtViewDescription.scrollEnabled=FALSE;
            }
            [myScroll addSubview:btnItem];
            [myScroll addSubview:txtViewDescription];
            [btnItem release];
            myScroll.scrollsToTop = NO;
            [txtViewDescription release];
            cxs += myScroll.frame.size.width;

        }
    }
    sqlite3_finalize(statement);

} 
else 
{
    sqlite3_close(database);
    NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}

[myScroll setContentSize:CGSizeMake(cxs, [myScroll bounds].size.height)];
if (intOID=1) {
    btnPrevDream.enabled = FALSE;

}
int page;
if(objAppdelDreamDetail.intPageCount>0)
{
    page=objAppdelDreamDetail.intPageCount;
    //NSLog(@"%d",page);

}
else 
{
    page=objAppdelDreamDetail.intPageCount;
    //NSLog(@"%d",page);
}
[myScroll setContentOffset:CGPointMake(320 * page, 0) animated:YES];

}

按钮事件...........

- (IBAction)actionShowDreamImage:(id)sender {     如果(!flgFaded)     {         tbarFooter.hidden = TRUE;         tbarHeader.hidden = TRUE;         lblNavTitle.hidden = TRUE;         lblNavEdit.hidden = TRUE;         lblNavPls.hidden = TRUE;         //txtViewDescription.hidden = TRUE;

    for(int i=1;i<[arrDream count];i++)
    {
        [[myScroll viewWithTag:1] setHidden:YES];
        txtViewDescription.tag=i;
        txtViewDescription.hidden=TRUE;

    }

}
else
{
    tbarFooter.hidden = FALSE;
    tbarHeader.hidden = FALSE;
    lblNavTitle.hidden = FALSE;
    lblNavEdit.hidden = FALSE;
    lblNavPls.hidden = FALSE;
    txtViewDescription.hidden = FALSE;
}
flgFaded = !flgFaded;

}

1 个答案:

答案 0 :(得分:0)

仅更改按钮点击事件方法

.............

-(IBAction)actionShowDreamImage:(id) sender {

if(!flgFaded)
    {
        tbarFooter.hidden = TRUE;
        tbarHeader.hidden = TRUE;
        lblNavTitle.hidden = TRUE;
        lblNavEdit.hidden = TRUE;
        lblNavPls.hidden = TRUE;
        for(int i=1;i<[arrDream count];i++)

{

for(UITextView *txtview in myScroll.subviews)

{

if(txtview.tag==i)
                {
                    txtview.hidden=YES;
                }
            }
        }

    }
    else
    {
        tbarFooter.hidden = FALSE;
        tbarHeader.hidden = FALSE;
        lblNavTitle.hidden = FALSE;
        lblNavEdit.hidden = FALSE;
        lblNavPls.hidden = FALSE;
        for(int i=1;i<[arrDream count];i++)
        {
            for(UITextView *txtview in myScroll.subviews)
            {
                if(txtview.tag==i)
                {
                    txtview.hidden=NO;
                }
            }

        }
    }
    flgFaded = !flgFaded;
}