多选表格视图 - 当部分展开/折叠时,在自定义标题中旋转图像

时间:2018-01-13 05:16:31

标签: ios swift uitableview uiimageview

问题:展开某个部分时,部分标题中的箭头会旋转指向上方。当我点击一个单元格时,箭头开始指向下方&顺时针旋转指向上方(箭头“抽搐”)。

enter image description here

如何摆脱箭头的“抽搐”?我希望箭头在展开部分时指向上方,并在部分折叠时指向下方。

CollapsibleFilterTableViewHeader

func setExpanded(expanded: Bool) {
    //Get angle of arrow (0.0 for pointing up or 180.0 for pointing down)
    let rad: Double = atan2( Double(arrowImageView.transform.b), Double(arrowImageView.transform.a))
    let deg: CGFloat = CGFloat(rad) * (CGFloat(180) / CGFloat.pi )

    if (expanded && deg == 0.0) {
        arrowImageView.rotate(.pi)
    }
}

FiltersViewController

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        header.setExpanded(expanded: filterSection.isExpanded)
        header.delegate = self
        return header
    }

func toggleSection(header: CollapsibleFilterTableViewHeader, section: Int) {
        let isExpanded = !filterSection.isExpanded

        // Toggle isExpanded
        filterSection.isExpanded = isExpanded
        header.setExpanded(expanded: isExpanded)

        filtersTableView.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
    }

来源:Stackoverflow QuestionMedium Article

2 个答案:

答案 0 :(得分:2)

  

请尝试此代码

  func setExpanded(expanded: Bool) {

  if (expanded) {
       arrowImageView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi));

  }else{
        arrowImageView.transform = CGAffineTransform(rotationAngle: 0);
  }

答案 1 :(得分:1)

试试这个

          <div class="col-xs-3">
            <button class="btn btn-sq-sm" ng-click="calc.view(7)">
                <p>7</p>
            </button>
          </div>

展开时设置旋转,否则提供import random from random import* t = 100 wmph = 51 h = 25 randwmph = random.randint(1, 99) print ("\nDynamic Weather Simulator | V.004\n") while True: if t >= 0 and t <= 150: print("\nHumidity:",h) print("\nTemperature:",t) print("\nWindSpeed:",wmph) print("\n________________\n") if t >= 5 and t <= 100: h = h + 0.6 if h >= 50 and t >= 33: print("\nRAINFALL\n") if h >= 50 and t <= 32: print("\nSNOWFALL\n") if h >= 55: h = h - 20 if wmph >= 30: t = t - 2 if wmph <= 29: t = t + 1 if wmph >= 60: wmph = wmph - randwmph # UNABLE TO USE THIS VARIABLE AS A NUMBER, EVEN THOUGH IT IS ASSIGNED AS A RANDOM NUMBER BETWEEN 1 and 99 else: wmph = wmph + 4 重置

希望它对你有所帮助