当在ios中的按钮上添加为子视图时,如何在uiwebview中获取userintraction

时间:2014-04-03 04:26:43

标签: uiwebview

我有一个按钮执行一些操作,添加了uiwebview作为按钮的子视图以加载一个小的gif动画,我可以点击按钮来执行任务但我需要在点击网络时执行相同的操作图。

-(void)numeritsIphone4{
    arrayButtonNames = @[@"Button1.png",@"Button2",@"Button3",@"Button4",@"Button5.png",@"Button6.png",@"Button7.png",@"Button8.png",@"Button9.png",@"Button10.png"];


    float y = 20;
    int x = 3;
    int count = 0;

       for (int i = 0 ; i < 10; i++)
    {
        count ++;

        buttonsarray[i] = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        buttonsarray[i].frame =  CGRectMake(x, y, 155, 90);
        buttonsarray[i].tag = i;
        [buttonsarray[i] setBackgroundImage:[UIImage imageNamed:[arrayButtonNames objectAtIndex:i]] forState:UIControlStateNormal];


        [buttonsarray[i].titleLabel setFont:[UIFont fontWithName:@"Verdana"  size:80]];
        [buttonsarray[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //buttonsarray[i].titleLabel.textAlignment = UITextAlignmentLeft;
        buttonsarray[i].contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [buttonsarray[i] setTitle:[NSString stringWithFormat:@"%d",digit] forState:UIControlStateNormal];

        digit ++;
        character = [[UIWebView alloc]initWithFrame:CGRectMake(100, 30, 25, 25)];
        NSURL *url=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Star" ofType:@"gif"]];
        character.opaque = NO;
        character.backgroundColor = [UIColor clearColor];
        character.scrollView.scrollEnabled = NO;
        [character loadRequest:[NSURLRequest requestWithURL:url]];
        character.userInteractionEnabled = YES;
        [buttonsarray[0] addSubview:character];
        [character release];
        [url release];
        [buttonsarray[i] addTarget:self action:@selector(performOperation4:) forControlEvents:UIControlEventTouchUpInside];
        x = x + 159;
        [self.view addSubview:buttonsarray[i]];
        if(count == 2)
        {
            count = 0;
            x = 3;
            y = y+ 92;
        }
    }

1 个答案:

答案 0 :(得分:0)

可能的做法是向UITapGestureRecognizer控件添加UIWebView,并在手势识别时调用相同的函数。

注意:这样,如果你的UIWebView页面上有一些按钮,链接等,那么你有限制,那个按钮,链接可能没有触发。所以试一试,看看它是否对你有帮助。