You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CocoaPods遇问题:设置popupHeight提示只读属性无法赋值

Fixing "Cannot assign to property: 'popupHeight' is a get-only property" Error

Hey there! Let's break down what's happening here and how to fix it.

The error you're seeing means that the popupHeight property on BottomPopupViewController is designed to be read-only—you can't directly assign a value to it like you tried with popupVC.popupHeight = 50.0. Most CocoaPods popup components use this pattern to let you customize the height by overriding the property instead of setting it directly.

Here's the most common solution:

Subclass BottomPopupViewController and override the popupHeight getter to return your desired height:

import UIKit
// Assuming BottomPopupViewController is imported from the pod

class CustomBottomPopupVC: BottomPopupViewController {
    // Override the read-only property to return your custom height
    override var popupHeight: CGFloat {
        return 50.0
    }
}

Then update your original code to instantiate this subclass instead:

@IBAction func testBtnPressed(_ sender: Any) {
    guard let popupVC = storyboard?.instantiateViewController(withIdentifier: "popup") as? CustomBottomPopupVC else { return }
    popupVC.popupDelegate = self
    present(popupVC, animated: true, completion: nil)
}

Other things to check:

  • Some similar components might provide a writable alternative property (like preferredPopupHeight or customPopupHeight). If you haven't already, double-check the component's internal docs or header files to see if such a property exists—if it does, you can use that instead of subclassing.
  • If the component supports custom initialization, look for an init method that accepts a height parameter (e.g., init(height: CGFloat)), which would let you set the height when creating the view controller.

This approach works because the original BottomPopupViewController likely uses the popupHeight property internally to calculate the popup's layout, and overriding it lets you inject your custom value.

内容的提问来源于stack exchange,提问作者user12473575

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:52:19