LoginSignup
5
3

More than 3 years have passed since last update.

iOS13のセルのclipsToBoundsにつまずいた

Last updated at Posted at 2019-12-08

はじめに

iOS13 にアップデートすると下記のような画面に遭遇。

ios13

しんぐるとんが見切れてる:poop:

対応

AccessoryDisclosure Indicator に設定しているので contentView の範囲は下の青い範囲。とりあえず clipsToBounds があやしい。

layout

デフォルトでセルの contentViewclipsToBoundstrue になってるので false に設定。

clip

いけた:star2:

after

調査

とりあえず表示できましたが一応調査。
iOS13 以上でなる模様。

iOS12.4.1 iOS13.0
ios12 ios13

そもそもなんで iOS13 未満は clipsToBoundstrue なのに表示されるんだ??

調べてみると下記がヒットした。(公式はみつからなかった...)

詳しくはわかりませんが iOS7.1 の頃から UITableViewCellcontentViewclipsToBoundstrue に設定されていても false になるらしい。

検証

iOS12.4.1 と iOS13 で UITableViewCellcontentView.clipsToBounds がどうなってるか調べてみました。

実装はこんな感じ

ViewController.swift
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  return 1
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TestTableViewCell
  return cell
}
TestTableViewCell.swift
override func awakeFromNib() {
  super.awakeFromNib()
  print("awakeFromNib clipsToBounds: \(contentView.clipsToBounds)")
}

override func layoutSubviews() {
  print("layoutSubviews clipsToBounds: \(contentView.clipsToBounds)")
}

iOS12.4.1 の結果

awakeFromNib clipsToBounds: true
layoutSubviews clipsToBounds: false

iOS13 の結果

awakeFromNib clipsToBounds: true
layoutSubviews clipsToBounds: true
layoutSubviews clipsToBounds: true

なんか2回呼ばれたけどとりあえず clipsToBoundstrue のままになってる:exclamation:

さいごに

clipsToBoundsfalse にすることで対応しましたが、これでいいのかは不明...今のとこ iOS12 でも iOS13 でもおかしな表示にはなっていません。

そもそも View からはみ出したレイアウトってどうなんだっていうのはありますが:neutral_face:

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3