初见

文章 评论 浏览 31

初见 2025-02-21 01:37:45

您需要将字段从某些 Integerfield 更改为 Chardfield 。数据库将整数 +123 作为正数 123

You need to change field from some IntegerField to ChardField. Database treats integer +123 as simply positive number 123.

而从excel导入,+符号未插入数字字段,django

初见 2025-02-21 01:06:07

最简单的是使用用户函数对数组进行排序,而无需任何循环:
以下是一个示例:

   $array_compare= array("0" =>4,"1"=>2,"2"=>500,"3"=>100);

这将以截止的顺序排序:

usort($array_compare, function($a, $b) {
        return ($b['x1'] - $a['x1']) > 0 ? 1 :-1;
    });

这将按照申请顺序排序:

usort($array_compare, function($a, $b) {
        return ($b['x1'] - $a['x1']) < 0 ? 1 :-1;
    });

The simplest is to use usort function to sort array without any looping :
Below is an example :

   $array_compare= array("0" =>4,"1"=>2,"2"=>500,"3"=>100);

This will sort in desending order :

usort($array_compare, function($a, $b) {
        return ($b['x1'] - $a['x1']) > 0 ? 1 :-1;
    });

This will sort in asending order :

usort($array_compare, function($a, $b) {
        return ($b['x1'] - $a['x1']) < 0 ? 1 :-1;
    });

如何在PHP中对数组和数据进行排序?

初见 2025-02-20 19:22:02

因为您的变量是在全局范围中创建的。 还有更多信息。

Because your variable is created in the global scope. There more information.

方法范围

初见 2025-02-20 12:20:24

检查图像以查找罪魁祸首,

您可以更仔细地查看Docker图像,以找出哪些层占用了很多空间。要查看不同的层及其尺寸,您可以使用 Docker历史命令。
示例:

docker history <image-name>

方法获取较小图像

以改善图像大小的方法可以看待多阶段构建

一个非常好的博客,展示了如何在Python中实现多阶段的构建并创建较小的图像和更快的构建:(博客由三篇文章组成)

就像@pierpy指出的那样,另一个改进是使用Python图像的高山文化。例如:

FROM python:3.9-alpine

请参阅所有图像版本在这里

Inspect image to find culprit

You can look more closely at the docker image to find out which layers are taking up a lot of space. To look at the different layers and their sizes you can use the docker history command.
Example:

docker history <image-name>

Methods to get smaller images

To improve your image size you can look into multi-staged builds.

A really good blog that shows how to realize multi-stage builds in python and create smaller images and faster builds: (blog consists of three articles)

Another improvement would be, like @pierpy pointed out, to use the alpine-version of the python image. For example:

FROM python:3.9-alpine

See all the image versions here.

Python Docker的图像太大了

初见 2025-02-20 08:34:12

接口项目&gt;属性工具不是将版本从.NET标准更新为标准版本以外的其他版本的方式。正确/最简单的方法是直接在项目的.csproj文件中更新目标帧。

The interface Project > Property tools isn't the way to update version from .Net standard to other versions other than standard versions. The right/easiest way is updating the TargetFramework in .csproj file of the project directly.

使用升级工具从.NET标准迁移到.NET 6/8

初见 2025-02-20 05:24:06

我想您想使用自适应池层产生的嵌入以具有固定的输出尺寸。首先,您需要摆脱最后的线性层(请参阅这篇文章):

model = models.resnet152(pretrained=True)
newmodel = torch.nn.Sequential(*(list(model.children())[:-1]))

然后,您可以获取嵌入式并使用pytorch.cat进行串联:

out = model(X)
emb = torch.cat([out, X.shape])

I guess you want to use the embedding that are produced by the Adaptive Pooling layer to have a fixed output size. First you need to get rid of the last linear layer (see this post):

model = models.resnet152(pretrained=True)
newmodel = torch.nn.Sequential(*(list(model.children())[:-1]))

Then you can get the embeddings and use pytorch.cat for concatenation:

out = model(X)
emb = torch.cat([out, X.shape])

如何con绕重新连接输出和输入图像的原始大小?

初见 2025-02-19 18:12:02

您似乎有很多不必要的嵌入在额外的视图和堆栈视图中...

看看:

<”输入图像描述在这里”

这是该XIB的来源(取出空格,因此适合此答案):

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
 <device id="retina6_1" orientation="portrait" appearance="light"/>
 <dependencies>
 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
 <capability name="Safe area layout guides" minToolsVersion="9.0"/>
 <capability name="System colors in document resources" minToolsVersion="11.0"/>
 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
 </dependencies>
 <objects>
 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
 <view contentMode="scaleToFill" id="w35-oq-szw">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
 <subviews>
 <visualEffectView opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="req-q9-lx2">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="d1H-9Q-j7P">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
 <subviews>
 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="sSl-mz-1DQ">
 <rect key="frame" x="10" y="0.0" width="725" height="531"/>
 <subviews>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="fGC-p9-L4U">
 <rect key="frame" x="0.0" y="0.0" width="725" height="125.5"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1fo-rx-txj">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="7">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JkP-z1-kBt">
 <rect key="frame" x="147" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="8">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aA8-sE-uyJ">
 <rect key="frame" x="294" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="9">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JdT-jT-0wO">
 <rect key="frame" x="441" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="C">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MqJ-SJ-vgm">
 <rect key="frame" x="588" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="^">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="ryL-j9-8Gp">
 <rect key="frame" x="0.0" y="135.5" width="725" height="125"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ATt-PW-v4y">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="4">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ToS-iL-gQp">
 <rect key="frame" x="147" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="5">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OSw-U5-1GF">
 <rect key="frame" x="294" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="6">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Uiw-M5-1xf">
 <rect key="frame" x="441" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="-">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dHS-oz-6Ou">
 <rect key="frame" x="588" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="/">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="JRw-LQ-aMf">
 <rect key="frame" x="0.0" y="270.5" width="725" height="125.5"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mal-m2-BW0">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="1">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KI1-ty-RLg">
 <rect key="frame" x="147" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="2">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5EU-9l-FVK">
 <rect key="frame" x="294" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="3">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y6Q-JT-JWy">
 <rect key="frame" x="441" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="+">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="G9r-jQ-QQ9">
 <rect key="frame" x="588" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="x">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="Uw9-qZ-Dfo">
 <rect key="frame" x="0.0" y="406" width="725" height="125"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8ld-d6-RQK">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title=".">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mBP-LN-MlY">
 <rect key="frame" x="147" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="0">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nde-Sc-JPt">
 <rect key="frame" x="294" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="D">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dGq-08-Kzm">
 <rect key="frame" x="441" y="0.0" width="284" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="=">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 </subviews>
 <constraints>
 <constraint firstItem="nde-Sc-JPt" firstAttribute="width" secondItem="5EU-9l-FVK" secondAttribute="width" id="4El-5L-MaG"/>
 <constraint firstItem="mBP-LN-MlY" firstAttribute="width" secondItem="KI1-ty-RLg" secondAttribute="width" id="Htd-Ko-RcX"/>
 <constraint firstItem="8ld-d6-RQK" firstAttribute="width" secondItem="mal-m2-BW0" secondAttribute="width" id="m9s-WZ-peK"/>
 </constraints>
 </stackView>
 </subviews>
 <constraints>
 <constraint firstItem="sSl-mz-1DQ" firstAttribute="top" secondItem="d1H-9Q-j7P" secondAttribute="top" id="Db1-iD-Elh"/>
 <constraint firstAttribute="trailing" secondItem="sSl-mz-1DQ" secondAttribute="trailing" constant="10" id="KbS-0k-Ie2"/>
 <constraint firstItem="sSl-mz-1DQ" firstAttribute="leading" secondItem="d1H-9Q-j7P" secondAttribute="leading" constant="10" id="TJv-db-APH"/>
 <constraint firstAttribute="bottom" secondItem="sSl-mz-1DQ" secondAttribute="bottom" id="g6s-Ye-LzN"/>
 </constraints>
 </view>
 <blurEffect style="systemThinMaterial"/>
 </visualEffectView>
 </subviews>
 <viewLayoutGuide key="safeArea" id="V0A-kF-WY5"/>
 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
 <constraints>
 <constraint firstItem="req-q9-lx2" firstAttribute="leading" secondItem="V0A-kF-WY5" secondAttribute="leading" id="0fX-Cx-EME"/>
 <constraint firstItem="req-q9-lx2" firstAttribute="trailing" secondItem="V0A-kF-WY5" secondAttribute="trailing" id="Jvp-Gw-hsl"/>
 <constraint firstItem="req-q9-lx2" firstAttribute="top" secondItem="w35-oq-szw" secondAttribute="top" id="hrp-Zn-ETe"/>
 <constraint firstAttribute="bottom" secondItem="req-q9-lx2" secondAttribute="bottom" id="kDe-Se-hCP"/>
 </constraints>
 <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
 <point key="canvasLocation" x="621" y="728"/>
 </view>
 </objects>
 <resources>
 <systemColor name="systemBackgroundColor">
 <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 </systemColor>
 </resources>
</document>

You have what appears to be a lot of unneeded embedding in extra views and stack views...

Take a look at this:

enter image description here

Here's the source for that xib (took out whitespace so it would fit in this answer):

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
 <device id="retina6_1" orientation="portrait" appearance="light"/>
 <dependencies>
 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
 <capability name="Safe area layout guides" minToolsVersion="9.0"/>
 <capability name="System colors in document resources" minToolsVersion="11.0"/>
 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
 </dependencies>
 <objects>
 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
 <view contentMode="scaleToFill" id="w35-oq-szw">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
 <subviews>
 <visualEffectView opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="req-q9-lx2">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="d1H-9Q-j7P">
 <rect key="frame" x="0.0" y="0.0" width="745" height="531"/>
 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
 <subviews>
 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="sSl-mz-1DQ">
 <rect key="frame" x="10" y="0.0" width="725" height="531"/>
 <subviews>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="fGC-p9-L4U">
 <rect key="frame" x="0.0" y="0.0" width="725" height="125.5"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1fo-rx-txj">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="7">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JkP-z1-kBt">
 <rect key="frame" x="147" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="8">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aA8-sE-uyJ">
 <rect key="frame" x="294" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="9">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JdT-jT-0wO">
 <rect key="frame" x="441" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="C">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MqJ-SJ-vgm">
 <rect key="frame" x="588" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="^">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="ryL-j9-8Gp">
 <rect key="frame" x="0.0" y="135.5" width="725" height="125"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ATt-PW-v4y">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="4">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ToS-iL-gQp">
 <rect key="frame" x="147" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="5">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OSw-U5-1GF">
 <rect key="frame" x="294" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="6">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Uiw-M5-1xf">
 <rect key="frame" x="441" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="-">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dHS-oz-6Ou">
 <rect key="frame" x="588" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="/">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="JRw-LQ-aMf">
 <rect key="frame" x="0.0" y="270.5" width="725" height="125.5"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mal-m2-BW0">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="1">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KI1-ty-RLg">
 <rect key="frame" x="147" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="2">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5EU-9l-FVK">
 <rect key="frame" x="294" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="3">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y6Q-JT-JWy">
 <rect key="frame" x="441" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="+">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="G9r-jQ-QQ9">
 <rect key="frame" x="588" y="0.0" width="137" height="125.5"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="x">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 <stackView opaque="NO" contentMode="scaleToFill" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="Uw9-qZ-Dfo">
 <rect key="frame" x="0.0" y="406" width="725" height="125"/>
 <subviews>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8ld-d6-RQK">
 <rect key="frame" x="0.0" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title=".">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mBP-LN-MlY">
 <rect key="frame" x="147" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="0">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nde-Sc-JPt">
 <rect key="frame" x="294" y="0.0" width="137" height="125"/>
 <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="D">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dGq-08-Kzm">
 <rect key="frame" x="441" y="0.0" width="284" height="125"/>
 <color key="backgroundColor" red="0.97410839800000004" green="0.8403052688" blue="0.2821659446" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
 <color key="tintColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 <state key="normal" title="Button"/>
 <buttonConfiguration key="configuration" style="plain" title="=">
 <fontDescription key="titleFontDescription" type="system" pointSize="40"/>
 </buttonConfiguration>
 </button>
 </subviews>
 </stackView>
 </subviews>
 <constraints>
 <constraint firstItem="nde-Sc-JPt" firstAttribute="width" secondItem="5EU-9l-FVK" secondAttribute="width" id="4El-5L-MaG"/>
 <constraint firstItem="mBP-LN-MlY" firstAttribute="width" secondItem="KI1-ty-RLg" secondAttribute="width" id="Htd-Ko-RcX"/>
 <constraint firstItem="8ld-d6-RQK" firstAttribute="width" secondItem="mal-m2-BW0" secondAttribute="width" id="m9s-WZ-peK"/>
 </constraints>
 </stackView>
 </subviews>
 <constraints>
 <constraint firstItem="sSl-mz-1DQ" firstAttribute="top" secondItem="d1H-9Q-j7P" secondAttribute="top" id="Db1-iD-Elh"/>
 <constraint firstAttribute="trailing" secondItem="sSl-mz-1DQ" secondAttribute="trailing" constant="10" id="KbS-0k-Ie2"/>
 <constraint firstItem="sSl-mz-1DQ" firstAttribute="leading" secondItem="d1H-9Q-j7P" secondAttribute="leading" constant="10" id="TJv-db-APH"/>
 <constraint firstAttribute="bottom" secondItem="sSl-mz-1DQ" secondAttribute="bottom" id="g6s-Ye-LzN"/>
 </constraints>
 </view>
 <blurEffect style="systemThinMaterial"/>
 </visualEffectView>
 </subviews>
 <viewLayoutGuide key="safeArea" id="V0A-kF-WY5"/>
 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
 <constraints>
 <constraint firstItem="req-q9-lx2" firstAttribute="leading" secondItem="V0A-kF-WY5" secondAttribute="leading" id="0fX-Cx-EME"/>
 <constraint firstItem="req-q9-lx2" firstAttribute="trailing" secondItem="V0A-kF-WY5" secondAttribute="trailing" id="Jvp-Gw-hsl"/>
 <constraint firstItem="req-q9-lx2" firstAttribute="top" secondItem="w35-oq-szw" secondAttribute="top" id="hrp-Zn-ETe"/>
 <constraint firstAttribute="bottom" secondItem="req-q9-lx2" secondAttribute="bottom" id="kDe-Se-hCP"/>
 </constraints>
 <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
 <point key="canvasLocation" x="621" y="728"/>
 </view>
 </objects>
 <resources>
 <systemColor name="systemBackgroundColor">
 <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
 </systemColor>
 </resources>
</document>

如何将堆栈视图与4个元素和堆栈视图相结合,并在XIB中使用5个元素?

初见 2025-02-19 15:40:28

声明基于范围的作品,资源将在范围末尾处置,因此下一个:

public Stream GenerateReport()
{
    using (var reportContext = new ReportRenderContext(this.ReportTemplate))
    {
        reportContext.Render();
    }

    return this.FileStream;
}

不是类似的to:

public Stream GenerateReport()
{
    using var reportContext = new ReportRenderContext(this.ReportTemplate);
    reportContext.Render();
    return this.FileStream;
}

后一个类似于:

public Stream GenerateReport()
{
    using (var reportContext = new ReportRenderContext(this.ReportTemplate))
    {
        reportContext.Render();
        return this.FileStream;
    }
} 

在某些情况下可能会有所不同,因此由于该编译器不会产生警告(编译器非常聪明并且同时非常愚蠢,它并不“真正”知道什么 this.fileStream 这样做。 this.fileStream 将引入运行时错误或 this.fileStream 可以是一个相对较长的操作,并且 dispose 的主要目的之一就是将不需要它们,就会有“反向”示例href =“ https://stackoverflow.com/a/19103343/2501279”> async上下文)。

using declaration works based on scope, resource will be disposed at the end of the scope, so the next one:

public Stream GenerateReport()
{
    using (var reportContext = new ReportRenderContext(this.ReportTemplate))
    {
        reportContext.Render();
    }

    return this.FileStream;
}

Is not analogous to:

public Stream GenerateReport()
{
    using var reportContext = new ReportRenderContext(this.ReportTemplate);
    reportContext.Render();
    return this.FileStream;
}

The latter one is analogous to:

public Stream GenerateReport()
{
    using (var reportContext = new ReportRenderContext(this.ReportTemplate))
    {
        reportContext.Render();
        return this.FileStream;
    }
} 

Which can have difference in some cases, so due to this compiler will not produce the warning (compiler is very smart and very dumb at the same moment, it does not "really" know what this.FileStream does. For example it can access the same resource as ReportRenderContext (like some file in non-shareable fashion) and disposing after return this.FileStream will introduce runtime error. Or this.FileStream can be just a relatively long operation and one of the main purposes of Dispose is to free resources as soon as they are not needed. There is "reverse" example when the 2nd snippet can fix a "bug" - in async context).

csharp_prefer_simple_using_statement / iDE0063未出现时出现

初见 2025-02-19 04:37:55

sts:externalId (<代码>: 。)将修复错误。

frommanagedPolicyName 方法“导入”对现有托管策略的引用。要创建一个新的,请实例化a 托管policy 构造: new Iam.managedpolicy(this,...)

sts:ExternalId (: not .) will fix the error.

The fromManagedPolicyName method "imports" a reference to an existing Managed Policy. To create a new one, instantiate a ManagedPolicy construct: new iam.ManagedPolicy(this, ...)

AWS CDK IAM帐户信托角色赋予条件必须由供应商列出。错误

初见 2025-02-18 20:12:43

根据我们从评论中的讨论,您可以使用 value 内置函数[1]和的组合来实现所需的目标,而不是而不是三元操作员:

resource "azuread_group" "groups" {
  for_each           = local.groups
  display_name       = each.key
  security_enabled   = true
  assignable_to_role = true
  members = [ for u in values(azuread_user.users) : u.id if u.department == each.key ]
}

[[[ 1] https://www.terraform.io/langueage/language/functions/functions/values

As per our discussion from the comments, you can achieve what you want by using a combination of values built-in function [1] and if instead of the ternary operator:

resource "azuread_group" "groups" {
  for_each           = local.groups
  display_name       = each.key
  security_enabled   = true
  assignable_to_role = true
  members = [ for u in values(azuread_user.users) : u.id if u.department == each.key ]
}

[1] https://www.terraform.io/language/functions/values

使用Terraform创建用户,组和group_member

初见 2025-02-18 15:04:34

当我希望它与众不同时,我总是会获得相同的属性值。如果我直接称呼它,我每次都会收到随机结果...为什么会这样?

因为您是一次调用功能,并打印值4次。更确切地说,每次致电Rs.Value时,您都会获得不同的结果,并且您打电话一次并打印该值4次。
以下代码可能会帮助您

import random
import string

class RS:
    def __init__(self, length: int):
        self.N = length

    @property
    def value(self):
        return ''.join(random.choice(string.ascii_uppercase + string.digits)
                      for _ in range(self.N))
                      
class ABC:
    def __init__(self, length: int):
        self.N = length
        self.rs = RS(self.N)
        
    def print_times(self):
        for i in range(4):
            print(self.rs.value)
                    
a = ABC(10)
a.print_times()

I always get the same value of a property when I want it to be different. If I call it directly, I get random results every time... Why is it happening so?

Because you are calling function once and printing value 4 times. More precisely, each time you call rs.value you get different result, and you are calling once and printing that value 4 times.
Below code might help you,

import random
import string

class RS:
    def __init__(self, length: int):
        self.N = length

    @property
    def value(self):
        return ''.join(random.choice(string.ascii_uppercase + string.digits)
                      for _ in range(self.N))
                      
class ABC:
    def __init__(self, length: int):
        self.N = length
        self.rs = RS(self.N)
        
    def print_times(self):
        for i in range(4):
            print(self.rs.value)
                    
a = ABC(10)
a.print_times()

使用@property从另一类生成随机字符串

初见 2025-02-18 02:34:21

使用单个滤波器条件并使用 .distinctinct (…) &nbsp; [django-doc] 返回不同的 dwcloudsystem s:

from django.db.models import Q

DWCloudSystem.objects.filter(
    Q(isShared=False, company_key=comp) |
    Q(isShared=True, location__owners=comp)
).distinct()

Use a single filter condition and use .distinct(…) [Django-doc] to return distinct DwCloudSystems:

from django.db.models import Q

DWCloudSystem.objects.filter(
    Q(isShared=False, company_key=comp) |
    Q(isShared=True, location__owners=comp)
).distinct()

Django查询与冲突的字段返回重复答案

初见 2025-02-17 20:15:29

对于我的实际数据集,我使用:

vars <- names(df) 

num<- seq(3, length(vars)-1,1)

我从3开始启动序列,因为我有两个ID变量(是字符串)。

for (i in num ) {
  
  df[paste0("d_", vars[i],"_",vars[i+1])]<-(df[,i+1]/df[,i]-1)
}

现在的问题是,我还计算了一个变量的最后一个阶段与下一个变量的第一个阶段之间的变化,因此我必须通过两个时期的组合删除这些列(在我的情况3&amp; 6)中:

df <- df %>% select(-c(contains("3") & contains("6")))

For my actual dataset I use:

vars <- names(df) 

num<- seq(3, length(vars)-1,1)

I start the sequence at 3, because I have two ID variables (that are strings).

for (i in num ) {
  
  df[paste0("d_", vars[i],"_",vars[i+1])]<-(df[,i+1]/df[,i]-1)
}

The issue now is that I also calculate the change between the last period of one variable and the first period of the next variable, so I have to delete those columns with the combination of the two periods (in my case 3 & 6):

df <- df %>% select(-c(contains("3") & contains("6")))

将静态值的面板数据转换为几个变量的更改的面板数据集

初见 2025-02-17 17:52:14

你的别名错了

Alias /static/ /home/pi/myproject/myprojectenv/myproject/static/

Your alias is wrong

Alias /static/ /home/pi/myproject/myprojectenv/myproject/static/

Django Apache设置 - 禁止错误403

初见 2025-02-17 12:15:14

我知道您的问题正在处理输入。因此,您可以将它们作为字符串输入并将其转换为特定类型,例如:

import math


def get_sqrt(input_number: str) -> float:
    """Return square root of input_number if in the form "sqrt(number)" (e.g. sqrt(2))"""
    value = float(input_number[input_number.find("(") + 1 : input_number.find(")")])
    return math.sqrt(value)


def get_pi(input_number: str) -> float:
    """Return pi value if input_number in the form "pi" """
    return math.pi


def get_division(input_number: str) -> float:
    """Return division value if input_number in the form "a/b" (e.g. 2/5)"""
    value = float(input_number.split("/")[0]) / float(input_number.split("/")[1])

    return value


def get_complex(input_number: str) -> complex:
    """Return complex value of input_number in the form "a+bj" (e.g. 1+2j)"""
    return complex(input_number)


def get_correct_number(input_number: str):
    str_patterns = {"sqrt": get_sqrt, "pi": get_pi, "/": get_division, "j": get_complex}

    for str_pattern, func in str_patterns.items():
        if str_pattern in input_number:
            return func(input_number)

    return float(input_number)


if __name__ == "__main__":
    # If you want to fill your list of values
    my_own_list = ["sqrt(2)", "pi", "1/2", "0", "4", "-4"]
    my_values = []

    print("Number -> Type")
    for input_number in my_own_list:
        number = get_correct_number(input_number)
        print(number, "->", type(number))
        my_values.append(number)

    print("\nList of converted values: ")
    print(my_values)

    # If you want to input values manually
    dont_stop = True
    my_values = []

    print("\nManual input\n")
    while dont_stop:
        input_number = input("Enter your number: ")
        if input_number:
            number = get_correct_number(input_number)
            print("Number -> Type")
            print(number, "->", type(number))
            my_values.append(number)
        else:
            dont_stop = False

    print("\nList of converted values: ")
    print(my_values)

在这里,终端上输入/输出的一个例子:

Number -> Type
1.4142135623730951 -> <class 'float'>
3.141592653589793 -> <class 'float'>
0.5 -> <class 'float'>
0.0 -> <class 'float'>
4.0 -> <class 'float'>
-4.0 -> <class 'float'>

List of converted values:
[1.4142135623730951, 3.141592653589793, 0.5, 0.0, 4.0, -4.0]

Manual input

Enter your number: 1
Number -> Type
1.0 -> <class 'float'>
Enter your number: 1/4
Number -> Type
0.25 -> <class 'float'>
Enter your number: sqrt(3)
Number -> Type
1.7320508075688772 -> <class 'float'>
Enter your number: 3+5j
Number -> Type
(3+5j) -> <class 'complex'>
Enter your number:

List of converted values:
[1.0, 0.25, 1.7320508075688772, (3+5j)]

我希望这会有所帮助!

PS:我没有使用任何正格来评估空间(例如,加上空间的空间会导致例外),也没有试图涵盖常见的加薪异常。

I understood that your issue is working on the inputs. So you could input them as strings and convert them to the specific type, like this:

import math


def get_sqrt(input_number: str) -> float:
    """Return square root of input_number if in the form "sqrt(number)" (e.g. sqrt(2))"""
    value = float(input_number[input_number.find("(") + 1 : input_number.find(")")])
    return math.sqrt(value)


def get_pi(input_number: str) -> float:
    """Return pi value if input_number in the form "pi" """
    return math.pi


def get_division(input_number: str) -> float:
    """Return division value if input_number in the form "a/b" (e.g. 2/5)"""
    value = float(input_number.split("/")[0]) / float(input_number.split("/")[1])

    return value


def get_complex(input_number: str) -> complex:
    """Return complex value of input_number in the form "a+bj" (e.g. 1+2j)"""
    return complex(input_number)


def get_correct_number(input_number: str):
    str_patterns = {"sqrt": get_sqrt, "pi": get_pi, "/": get_division, "j": get_complex}

    for str_pattern, func in str_patterns.items():
        if str_pattern in input_number:
            return func(input_number)

    return float(input_number)


if __name__ == "__main__":
    # If you want to fill your list of values
    my_own_list = ["sqrt(2)", "pi", "1/2", "0", "4", "-4"]
    my_values = []

    print("Number -> Type")
    for input_number in my_own_list:
        number = get_correct_number(input_number)
        print(number, "->", type(number))
        my_values.append(number)

    print("\nList of converted values: ")
    print(my_values)

    # If you want to input values manually
    dont_stop = True
    my_values = []

    print("\nManual input\n")
    while dont_stop:
        input_number = input("Enter your number: ")
        if input_number:
            number = get_correct_number(input_number)
            print("Number -> Type")
            print(number, "->", type(number))
            my_values.append(number)
        else:
            dont_stop = False

    print("\nList of converted values: ")
    print(my_values)

And here one example of input/output on the terminal:

Number -> Type
1.4142135623730951 -> <class 'float'>
3.141592653589793 -> <class 'float'>
0.5 -> <class 'float'>
0.0 -> <class 'float'>
4.0 -> <class 'float'>
-4.0 -> <class 'float'>

List of converted values:
[1.4142135623730951, 3.141592653589793, 0.5, 0.0, 4.0, -4.0]

Manual input

Enter your number: 1
Number -> Type
1.0 -> <class 'float'>
Enter your number: 1/4
Number -> Type
0.25 -> <class 'float'>
Enter your number: sqrt(3)
Number -> Type
1.7320508075688772 -> <class 'float'>
Enter your number: 3+5j
Number -> Type
(3+5j) -> <class 'complex'>
Enter your number:

List of converted values:
[1.0, 0.25, 1.7320508075688772, (3+5j)]

I hope that helps!

p.s.: I didn't use any regex to evaluate spaces (e.g. '2+ 5j' with space after plus would lead to an exception), neither tried to cover common raise exceptions.

如何在Manim中的数字线上添加我自己的数字?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文