小编use*_*552的帖子

iOS:为所有设备启动图像,包括iPad Pro

我遵循制作静态启动屏幕图像的指导原则.

在此输入图像描述

然而,然后我将图像作为LaunchImage添加到xcassets中

但是,他们没有按预期填写资产.有警告警告我需要有屏幕尺寸,如2208x1242等.我可以拥有应用程序所需的所有尺寸?

在此输入图像描述

另外,为什么没有iPad Pro发布图像?我该如何添加它?谢谢.

xcode ios xcasset launchimage

14
推荐指数
3
解决办法
1万
查看次数

iOS10后台获取

我试图实现后台提取,希望可以不时唤醒应用程序.

我做了这些:

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
        return true
      }

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    debugPrint("performFetchWithCompletionHandler")
    getData()
    completionHandler(UIBackgroundFetchResult.newData)
  }

  func getData(){
    debugPrint("getData")
  }
Run Code Online (Sandbox Code Playgroud)

我已经启用了后台提取功能.这就是我所做的一切.然后我运行应用程序.即使一小时后(手机睡了),这个功能也从未打过电话.

还有什么其他的事情可以让函数被调用?

ios swift background-fetch

12
推荐指数
2
解决办法
9468
查看次数

swift:nscoding decodeObject始终为nil

我在写一个名为Packet的对象时得到了以下代码,并通过Multipeer连接发送到另一端.但是,每当它尝试解码编码对象时,我都会收到以下错误.

  class Packet : NSObject, NSCoding {

  var tmp1: Double = 0
  var tmp2: Double = 0

  struct PropertyKey {
    static let tmp1Key = "tmp1Key"
    static let tmp2Key = "tmp2Key"
  }


  init(tmp1: Double, tmp2: Double) {
    self.tmp1 = tmp1
    self.tmp2 = tmp2
    super.init()
  }

  deinit {
  }

  required convenience init(coder aDecoder: NSCoder) {
    debugPrint("initcoder")
    let tmp1 = aDecoder.decodeObject(forKey: PropertyKey.tmp1Key) as! Double // crash here
    let tmp2 = aDecoder.decodeObject(forKey: PropertyKey.tmp2Key) as! Double
    self.init(tmp1: tmp1, tmp2: tmp2)
  }

  public func encode(with aCoder: …
Run Code Online (Sandbox Code Playgroud)

nscoding ios nskeyedunarchiver multipeer-connectivity swift

11
推荐指数
2
解决办法
2086
查看次数

SwiftUI 的 Text() 自动调整字体大小?

有没有办法根据要显示的文字长度自动调整字体大小?例如,通过设置帧大小?能否自动缩小字体大小,使显示字体的宽度保持不变?

var body: some View {
    
    VStack {
        ZStack {
            GeometryReader { g in
                ZStack {
                    
                    ScrollView(.vertical, showsIndicators: true, content: {
                    VStack {
                        ZStack {
                            VStack {
                                Image("cat")
                                    .resizable()
                                    .aspectRatio(contentMode: .fill)
                                    .frame(width:g.size.width, height:g.size.height/4*3)
                                    .clipped(antialiased:true)
                                    .shadow(radius:25, x:0, y:0)
                                
                                VStack (){
                                    HStack {
                                        VStack (alignment: .leading) {
                                            HStack {
                                                Text("XXXX").font(.title)
                                               
                                                        .font(.system(size:35)).foregroundColor(.black).shadow(radius: 5)
                                                })
                                                Spacer()
                                                

                                            }
                                            HStack {
                                                Text("xxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxx ").font(.title2) // very long text here
                                                Spacer()
                                            }
                                        }
                                    }
                                    
                                }
                                .padding()
                                .frame(width:g.size.width, height:g.size.height/4*1, alignment: .top)
                            }
                        }.frame(width: g.size.width, height: g.size.height, alignment: …
Run Code Online (Sandbox Code Playgroud)

swiftui

7
推荐指数
1
解决办法
4899
查看次数

iOS:我可以检测设备屏幕是否打开/关闭吗?

如何在 iOS 中检查屏幕是打开还是关闭?我想知道屏幕当前是否打开,即使我的应用程序在后台。我想要一个事件监听器。谢谢。

iphone screen ios swift

6
推荐指数
1
解决办法
4938
查看次数

iOS 11位置许可

我有一个应用程序,需要使用"始终"作为位置更新.但是,我发现在将设备升级到iOS11后,应用程序从未向我请求许可.

然后当我转到隐私>位置>时,"总是"和"使用中"的选择消失了.

我已经检查过需要在plist文件中添加"Privacy - Location Always Usage Description".我添加了,但它仍然是相同的,它无法跟踪位置.

我错过了更新我的代码的任何事情?

location core-location ios ios11

6
推荐指数
1
解决办法
3508
查看次数

swift:异步任务+完成

我对swift中的异步任务感到非常困惑.我想做的是这样的......

 func buttonPressed(button: UIButton) {
   // display an "animation" tell the user that it is calculating (do not want to freeze the screen
   // do some calculations (take very long time) at the background
   // the calculations result are needed to update the UI
 }
Run Code Online (Sandbox Code Playgroud)

我试着这样做:

func buttonPressed(button: UIButton) {
    let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
    dispatch_async(queue) { () -> Void in
       // display the animation of "updating"
       // do the math here
        dispatch_async(dispatch_get_main_queue(), {
          // update the UI
       }
    } …
Run Code Online (Sandbox Code Playgroud)

ios dispatch-async swift swift2

5
推荐指数
1
解决办法
5454
查看次数

Swift:AVPlayer释放内存/资源

我正在编写一个应用程序,需要根据用户的选择显示不同的视频.当用户选择视频时,将调用playVideo功能.视频播放完毕后,视频将再次隐藏.

我的代码如下:

var player: AVPlayer?


  func playVideo(String: videoFile) {
    self.videoView.isHidden = false
    let videoURL: NSURL = Bundle.main.url(forResource: videoFile, withExtension: "mp4")! as NSURL
    self.player = AVPlayer(url: videoURL as URL)
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = self.videoView.frame
    self.videoView.layer.addSublayer(playerLayer)
    let duration : Int64 = 0
    let preferredTimeScale : Int32 = 1
    let seekTime : CMTime = CMTimeMake(duration, preferredTimeScale)
    self.player?.seek(to: seekTime)
    self.player?.play()

    NotificationCenter.default.addObserver(self, selector: #selector(self.playerItemDidReachEnd), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player?.currentItem)
  }

@objc func playerItemDidReachEnd()
  {
    self.player?.pause()
    self.videoView.isHidden = true
    NotificationCenter.default.removeObserver(self)
  }
Run Code Online (Sandbox Code Playgroud)

但是,根据上面的代码,我有几个问题:

  1. 如何优雅地删除/取消分配播放器?如果只使用我当前的代码,它会占用大量内存吗?

  2. 每当用户按下按钮时,将调用playVideo功能,并创建并播放相应的播放器.这是正确的方法吗?有没有其他方法或更有效的方式或优雅的方式这样做? …

ios avplayer avplayerlayer swift avplayeritem

5
推荐指数
0
解决办法
1119
查看次数

C#:使用 Python.Runtime 未找到

我尝试使用 Python for .NET 嵌入 python 脚本。在 C# 程序中,我尝试导入该类

using Python.RunTime;
Run Code Online (Sandbox Code Playgroud)

但找不到。我无法找出其中的原因。我已经在我的 python 解释器中安装了 pythonnet。

我只是想通过以下代码来测试它:

using (Py.GIL)
{
  dynamic np = Py.Import("numpy");
  MessageBox.Show(np.cos(np.pi * 2));
}
Run Code Online (Sandbox Code Playgroud)

* 更新 *

我在 VS 项目中添加了引用 Python.Runtime.dll 。当执行时,它得到了System.BadImageFormatException。我不知道为什么会这样。

c# python python.net

4
推荐指数
1
解决办法
4702
查看次数

将json转换为python obj

我想将解析后的json数据转换为python对象.

这是我的json格式:

{
   "Input":{
      "filename":"abg.png",
      "fileSize":123456
   },
   "Output":{
      "filename":"img.png",
      "fileSize":1222,
      "Rect":[
         {
            "x":34,
            "y":51,
            "width":100,
            "height":100
         },
         {
            "x":14,
            "y":40,
            "width":4,
            "height":6
         }]
   }
}   
Run Code Online (Sandbox Code Playgroud)

我试图创建一个名为Region的类

class Region:
    def __init__(self, x, y, width, height):
        self.x=x
        self.y=y
        self.width=width
        self.height=height

    def __str__(self):
        return '{{"x"={1}, "y"={2}, "width"={3}, "height"={4}}'.format(self.left, self.top, self.width, self.height)

def obj_creator(d):
    return Region(d['x'], d['y'], d['width'], d['height'])
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用object_hook函数将数据加载到对象中:

for item in data['Output']['Rect']:
    region = json.loads(item, object_hook=obj_creator)
Run Code Online (Sandbox Code Playgroud)

但我发现它有错误说

TypeError: the JSON object must be str, bytes or bytearray, not 'dict'
Run Code Online (Sandbox Code Playgroud)

实际上我知道如果我的数据没有嵌套,如何将对象分配给python对象.但我没有使用嵌套的json数据.有什么建议吗?

谢谢.

python json

0
推荐指数
1
解决办法
67
查看次数