向视图添加动态按钮

时间:2013-12-12 13:45:27

标签: ios objective-c uiview uibutton uigesturerecognizer

Below is the image decription of what I need

我能够获得用户轻敲的身体部位的放大倍数。但是,如上所述,文本(图像中的“手腕”)应动态更改,具体取决于正文部分,它应该充当按钮这样当再次点击时,它会通过函数调用将用户带到不同的详细信息屏幕。我该如何实现此功能?我们欢迎使用代码段。

1 个答案:

答案 0 :(得分:0)

也许你可以用TapGestureRecognizer达到预期的效果?

在viewDidLoad中:

UITapGestureRecognizer *tapWrist = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedWrist)];
tapWrist.delegate = self;
[bodyView addGestureRecognizer:tapWrist];

添加方法:

- (void)tappedWrist
{
    // code here
}

不要忘记包括:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer  *)otherGestureRecognizer {
    return YES;
}

并将UIGestureRecognizerDelegate添加到头文件中。