ios _ self.view 宽高为 600 * 600 问题

本文介绍如何解决iOS应用中使用SwiftUI时View尺寸被固定为600x600的问题。通过在viewDidLoad方法中添加一行代码:self.view.frame=UIScreen.main.bounds,可以确保视图正确适配屏幕大小。文章还提供了额外资源链接,包括调整freeform和取消usetraitVariations的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

突然出现 veiw的宽高固定为600 * 600 了,莫民奇妙,百度各种资料
有改freeform的, 有取消 use trait Variations 的,总之解决不了自己问题,最终终于找到适合自己的

https://segmentfault.com/q/1010000011832479/a-1020000011832664

xib创建的Controller的View初始值就是(600,600), 你可以在viewWillAppear方法中添加创建的HUD, 或者是在 viewDidLoad 中设置View的Frame: self.view.frame = [UIScreen mainScreen].bounds.size然后添加HUD.

就是


  override func viewDidLoad() {
        super.viewDidLoad()
        self.view.frame = UIScreen.main.bounds   // 增加这一句 即可
        }

改freeform 连接

https://blog.youkuaiyun.com/u012129719/article/details/79820017

取消 use trait Variations 链接

https://blog.youkuaiyun.com/weixin_34336292/article/details/87502502

import cv2 import numpy as np import onnxruntime as ort from label_studio_ml.model import LabelStudioMLBase from urllib.request import urlopen class myModel(LabelStudioMLBase): def __init__(self, **kwargs): super(myModel, self).__init__(**kwargs) self.model = ort.InferenceSession("model_cache/yolov8n.onnx") self.input_name = self.model.get_inputs()[0].name self.classes = ["car_door", "front_cover", "rear_cover"] def predict(self, tasks, **kwargs): task = tasks[0] image_url = task['data']['image'] with urlopen(image_url) as resp: image = np.asarray(bytearray(resp.read()), dtype=np.uint8) image = cv2.imdecode(image, cv2.IMREAD_COLOR) input_tensor = self._preprocess(image) outputs = self.model.run(None, {self.input_name: input_tensor}) results = self._postprocess(outputs, image) avg_score = float(np.mean([r['score'] for r in results])) if results else 0.0 return { "results": [{ "result": results, "score": avg_score, "model_version": "yolov8n" }] } def _preprocess(self, img): img = cv2.resize(img, (640, 640)) img = img.transpose(2, 0, 1)[np.newaxis, ...].astype(np.float32) / 255.0 return img def _postprocess(self, outputs, original_img): outputs = np.array(outputs[0]) boxes = outputs[:, :4] scores = outputs[:, 4] class_ids = outputs[:, 5] label_studio_results = [] for box, score, cls_id in zip(boxes, scores, class_ids): if score < 0.5: continue label_studio_results.append({ "value": { "x": float(box[0] / 640 * 100), "y": float(box[1] / 640 * 100), "width": float((box[2] - box[0]) / 640 * 100), "height": float((box[3] - box[1]) / 640 * 100), "rectanglelabels": [self.classes[int(cls_id)]] }, "from_name": "bbox", "to_name": "image", "type": "rectangle", "score": float(score) }) return label_studio_results model_class = myModel 添加类别索引转换
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值