最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

macos - How is this frame size computed for a TextView - Stack Overflow

matteradmin6PV0评论

I've got the following xib: (minimal example stripped from a larger UI)

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
    <dependencies>
        <deployment identifier="macosx"/>
        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <customObject id="-2" userLabel="File's Owner" customClass="AboutWindowController"/>
        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
        <window id="5">
            <rect key="contentRect" x="641" y="589" width="538" height="337"/>
            <view key="contentView" id="123">
                <rect key="frame" x="1" y="1" width="523" height="188"/>
                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                <subviews>
                    <textView id="28">
                        <rect key="frame" x="0.0" y="0.0" width="523" height="188"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    </textView>
                </subviews>
            </view>
        </window>
    </objects>
</document>

After compilation, the NSTextView gets NSFrameSize with the height of 337, but I'd like to understand why. Why is it getting the height from the contentRect and not the frame of the view? Is there a specific documentation link I can find about it?

I found it surprising since this structure:

        <window id="5">
            <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
            <rect key="contentRect" x="641" y="589" width="538" height="337"/>
            <rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
            <view key="contentView" id="6">
                <rect key="frame" x="0.0" y="0.0" width="538" height="337"/>
                <subviews>
                    <textField verticalHuggingPriority="750" preferredMaxLayoutWidth="0.0" id="13">
                        <rect key="frame" x="190" y="288" width="158" height="29"/>

does result in the height/width defined in the frame rect. (NSFrame is {190, 288}, {158, 29})

Post a comment

comment list (0)

  1. No comments so far