複数のプロジェクトで再利用したい UIButton のカスタム サブクラスがあり、そのうちのいくつかはインターフェイス ビルダーとストーリーボードを使用し、一部は使用しない場合があります。ボタンのフレームをいくつかの場所に設定する必要があります。
追加すると
self.translatesAutoresizingMaskIntoConstraints = YES;
初期化では、すべてが正しく機能しているように見えますが、次のようになります。
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
Will attempt to recover by breaking constraint…etc
コンソールに記録されます。ただし、設定した場合
self.translatesAutoresizingMaskIntoConstraints = NO;
ボタンのサイズ変更は機能せず、ボタンは完全に壊れています。
エラーが正しいものに劣化しているように見えるため、エラーを抑制する方法はありますか、または何らかの方法で問題のある制約を手動で削除できますか?
ボタンが初期化された後に制約をダンプしようとしましたが、制約 AutoLayout が含まれていないようで、結局壊れてしまいます。
編集: 以下は、サンプル プロジェクトへのリンクと、私のボタン コードです。ストーリーボードで自動レイアウトがオフになっているとうまく機能しますが、自動レイアウトがオンになっていると、ボタンが原点に配置されているように見えます (initWithCoder が呼び出されたときに、ボタンにスーパービューや位置がないためと思われます)情報)。