UIButton does not work when it in UIScrollView

后端 未结 8 481
说谎
说谎 2020-12-01 10:38

My structure of views:

UITableView
  UITableViewCell
    UIScrollView
      CustomView
        UIButton

The problem is UIButton doesn\'t wo

8条回答
  •  不思量自难忘°
    2020-12-01 11:34

    I guess you need to set the button frame. By default if you use btn = [[UIButton alloc] init]; method to initialize button it will be UIButtonTypeCustom. Also set a background color to it for debugging purpose to note down where the button is actually placed. Now for your case you need to set the frame for that button like btn.frame = CGRectMake(0,0,100,100);

    For the inner UIScrollView implement this delegate method.

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view
      {
           return ![view isKindOfClass:[UIButton class]];
      }
    

    This may work.

提交回复
热议问题