小编Cha*_*esh的帖子

UICollectionView水平分页,页面之间有空格

我正在寻找一种UIPageViewController用a 替换原生水平分页的方法UICollectionView.

到目前为止,我做了以下事情:

let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.itemSize = collectionView.frame.size
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 10

collectionView.setCollectionViewLayout(layout, animated: false)
collectionView.isPagingEnabled = true
collectionView.alwaysBounceVertical = false
Run Code Online (Sandbox Code Playgroud)

这工作正常,我得到水平分页效果.

现在我想要添加的页面之间的水平空间(像你将做UIPageViewControllerOptionInterPageSpacingKeyUIPageViewController)

到目前为止,我无法在不损坏分页效果的情况下添加空格.我正在寻找与以下相同的行为UIPageViewController:单元格应该填满整个屏幕宽度,并且单元格之间的空间应该只在切换页面时可见.

uikit ios uipageviewcontroller uicollectionview uicollectionviewlayout

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

从iOS端在设备上显示之前可以更改推送通知消息吗?

显示我的推送通知消息是来自:+919687335565的消息

附截图:

在此输入图像描述

我只是想从这个联系人的姓名中获取这个+919687335565的姓名,Address book显示该联系人的姓名而不是电话号码push notification.

在显示之前notification我想用推送通知中的联系人姓名Chandresh替换电话号码+919687335565.

喜欢附上截图:

在此输入图像描述

push-notification apple-push-notifications ios

13
推荐指数
1
解决办法
6421
查看次数

添加效果后导出音频文件

我有一个音频文件,我想使用一些效果(如音高效果)处理,然后将最终结果写入文件.

在我处理文件并将其保存到光盘之前,让用户播放音高效果并实时收听变化.

这就是我做实时的事情:

let audioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: nil)
audioSession.setActive(true, error: nil)

audioEngine = AVAudioEngine()
audioFile = AVAudioFile(forReading: audioUrl!, error: nil)

audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)

changePitchEffect = AVAudioUnitTimePitch()
changePitchEffect.pitch = 1.0 // default
audioEngine.attachNode(changePitchEffect)

audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil)
audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil)

let frameCapacity = UInt32(audioFile.length)
let buffer = AVAudioPCMBuffer(PCMFormat: audioFile.processingFormat, frameCapacity: frameCapacity)
if audioFile.readIntoBuffer(buffer, error: nil) {

    audioEngine.startAndReturnError(nil)

    audioPlayerNode.scheduleBuffer(buffer, atTime: nil, options: .Loops, completionHandler: nil)

    audioPlayerNode.play() // start playing in a loop
}
Run Code Online (Sandbox Code Playgroud)

然后使用UISlider我让用户在循环中聆听音频的同时改变音高的值. …

avfoundation ios swift avaudioengine

12
推荐指数
1
解决办法
1332
查看次数

在iOS上分享视频到Instagram

是否可以在Instagram上分享视频而不将其保存到用户的相机胶卷?

这是我到目前为止所尝试的:

let instagramURL = URL(string: "instagram://app")!
  if (UIApplication.shared.canOpenURL(instagramURL)) {

      self.documentController = UIDocumentInteractionController(url: videoURL)
      self.documentController.delegate = self
      self.documentController.uti = "com.instagram.exlusivegram"
      self.documentController.presentOpenInMenu(from: self.view.frame, in: self.view, animated: true)

  } else {
      print(" Instagram isn't installed ")
  }  
Run Code Online (Sandbox Code Playgroud)

videoURL是我保存在Documents文件夹中的视频的URL.
如果我Instagram.igo在最后保存URL ,那么当我选择Instagram分享它时会打开如下:
在此输入图像描述

如果我在最后用.mov保存视频,那么Instagram分享似乎会打开一张照片(如视频缩略图),而不是视频.

ios uidocumentinteraction instagram uiactivityviewcontroller

8
推荐指数
1
解决办法
2500
查看次数

在 ios 上使用应用内购买进行购买(而非订阅)之前,如何处理免费试用

我想在我的 ios 应用程序上提供免费试用和购买(非消耗性应用程序内购买)的选项。我可以看到我可以提供试用版,然后订阅(自动续订订阅),但我个人不喜欢为一个简单的应用程序反复付费,但我确实想先尝试一下。在设置购买选项时有没有办法达到同样的效果?我意识到我可以跟踪下载后的第一次使用情况,但这提出了几个问题:

  1. Apple 现在会批准应用程序试用吗?之前它们已被拒绝,但那是在 IAP 和订阅可用之前!
  2. 如何防止用户删除应用程序(以及我可能存储的任何数据以了解他们已激活试用版)然后再次下载?

或者我是否必须屈服于有害的“订阅”模式或发布带有升级的“轻型”版本?上次我“轻装上阵”时,苹果坚持要我提供如此多的功能,我可能并没有关心完整版本 - 但那是不久前的事了。

iphone in-app-purchase ios

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

使用 AVPlayer 进行流式传输很慢

我使用 AVPlayer 从互联网流式传输 mp3 文件,它的工作速度非常慢。使用分析器我发现,它首先下载整个文件,然后开始播放。有什么解决方法吗?

现在,我正在使用此代码

if let player = player {
    NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

    let item = AVPlayerItem(url: url)

    player.replaceCurrentItem(with: item)
} else {
    player = AVPlayer(url: url)
}
player?.play()
Run Code Online (Sandbox Code Playgroud)

我尝试过的事情:

  • 将 player?.play() 移动到观察者,附加到项目的状态属性
  • 使用属性preferredForwardBufferDurationpreferredPeakBitRate

结果一直是下载整个音频文件,然后才开始播放。

请注意,问题是 - 播放器仅在整个文件下载后才开始播放,而我希望它流式传输 mp3。

ios avplayer swift

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

如何在Swift中心UIButton?

我有这个代码UIButton.我应该在我的改变CGRectMake设置我UIButton的屏幕中心为所有屏幕尺寸?

let loginBtn = UIButton(frame: CGRectMake(60, 360, 240, 40))
loginBtn.layer.borderColor = UIColor.whiteColor().CGColor
loginBtn.layer.borderWidth = 2
loginBtn.titleLabel!.font = UIFont.systemFontOfSize(24)
loginBtn.tintColor = UIColor.whiteColor()
loginBtn.setTitle("Login", forState: UIControlState.Normal)
self.view.addSubview(loginBtn)
Run Code Online (Sandbox Code Playgroud)

ios swift

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