我想动画一个对象,所以我声明一个约束并将其添加到视图中.然后我更新动画constant
内约束的属性UIView
.为什么这段代码没有移动对象?
UIView.animateWithDuration(1, animations: {
myConstraint.constant = 0
self.view.updateConstraints(myConstraint)
})
Run Code Online (Sandbox Code Playgroud) 我想设置UITextField
的borderColor
iOS中8斯威夫特.我尝试使用此代码:
myTextField.layer.borderColor = UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 )
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
UIColor不能转换为CGColor
我想无限期地旋转图像视图360度.
UIView.animate(withDuration: 2, delay: 0, options: [.repeat], animations: {
self.view.transform = CGAffineTransform(rotationAngle: 6.28318530717959)
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
UICollectionView
启用分页机制我做的很简单,一切正常.但是,当滚动到最后一页时,屏幕中的单元格数量不完全可见,最后一页包含上一页面的一些单元格.
如何扩大contentSize
的UICollectionView
,这样最后一页不包含前一页的任何细胞?
这里的一个例子:UICollectionView
水平滚动6个单元格,这样:
第1页: cell0 - cell1 - cell2 - cell3
滚动:cell2-cell3-cell4-cell5 //不期望:如何更改为:cell4 - 第2页中的单元格5.
摘要:
我想设置
collectionView.contentSize = numberOfPage * collectionView.frame
不
collectionView.contentSize = numberOfCell * (cellFrame + spacing)
我在动画中有这个代码:
image.frame = CGRectMake(x: x, y: y, width, height)
Run Code Online (Sandbox Code Playgroud)
我需要获取图像的x和y坐标.我发现了这个Objective-C代码:
CGPoint origin = imageView.frame.origin;
Run Code Online (Sandbox Code Playgroud)
一旦找到图像的x和y位置,我将需要对其进行转换.我将使用类似的东西:
image.frame = CGRectMake(x-50, y-50, width+500, height+500)
Run Code Online (Sandbox Code Playgroud)
...这样我就可以在屏幕上移动图像了.如何找到原始的x和y位置?
我想在Swift Playgrounds iPad应用程序上访问iPad的相机.我发现捕捉视频数据是不可能的,即使我的游乐场运行正常.
captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!)
,AVCaptureVideoDataOutputSampleBufferDelegate
协议的委托方法,没有被调用(可能是因为没有视频数据进入),而它在我的iOS应用程序中.
我的操场上的视图应该显示FaceTime摄像机视图.为什么我不能显示相机输出,即使Apple明确表示允许这样做?此外,Playground应用程序在我打开操场时会立即询问相机权限,因此应该以某种方式允许它.
import UIKit
import CoreImage
import AVFoundation
import ImageIO
import PlaygroundSupport
class Visage: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
var visageCameraView : UIView = UIView()
fileprivate var faceDetector : CIDetector?
fileprivate var videoDataOutput : AVCaptureVideoDataOutput?
fileprivate var videoDataOutputQueue : DispatchQueue?
fileprivate var cameraPreviewLayer : AVCaptureVideoPreviewLayer?
fileprivate var captureSession : AVCaptureSession = AVCaptureSession()
fileprivate let notificationCenter : NotificationCenter = NotificationCenter.default
override init() {
super.init()
self.captureSetup(AVCaptureDevicePosition.front)
var faceDetectorOptions …
Run Code Online (Sandbox Code Playgroud) 我需要改变disclosureIndicatorView
配件的颜色UITableViewCell
.我认为有两种方法可以完成这项任务,但我无法弄清楚哪一种是最佳选择.所以这就是我认为我能做到的.
有一个属性UITableViewCell
- accessoryView
.所以我可以使用setAccessoryView:(UIView *)view
并传递视图作为UIImageView
持有我想要的图像.
我编写了一个实用程序类,它为我的单元格创建内容视图(像背景颜色,添加其他东西等等),然后将此内容视图添加到单元格中UITableViewDelegate
.另一种选择是绘制UIImage
覆盖实用程序类的drawRect
方法CustomContentView
.
执行选项1 - 我可以通过苹果方式完成工作.只要给他们观点,他们就会完成其余的工作.但我想UIView
在每一行中添加一个新对象可能会成为一个繁重的对象分配并降低帧速率.与UIImage
我的一个对象相比contentView
.我相信UIImage
比较轻UIView
.
请抛出一些轻松的人并帮我决定.
在Objective-C中,我使用以下代码
将Int
变量转换NSData
为字节数据包.
int myScore = 0;
NSData *packet = [NSData dataWithBytes:&myScore length:sizeof(myScore)];
Run Code Online (Sandbox Code Playgroud)将转换后的NSData
变量用于方法.
[match sendDataToAllPlayers:
packet withDataMode: GKMatchSendDataUnreliable
error: &error];
Run Code Online (Sandbox Code Playgroud)我尝试将Objective-C代码转换为Swift:
var myScore : Int = 0
func sendDataToAllPlayers(packet: Int!,
withDataMode mode: GKMatchSendDataMode,
error: NSErrorPointer) -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法将Int
变量转换为a NSData
并将其用作方法.我怎样才能做到这一点?
我注意到当调用setLayout:animated
a UICollectionView
在两个布局之间切换时,当前可见的单元格不符合zIndex
它的布局属性已被设置layoutAttributesForItemAtIndexPath:
.
例如,如果我有一个UICollectionView
with UICollectionViewFlowLayout
,则将其设置minimumLineSpacing
为负数,以便单元格重叠,然后zIndex
在每个单元格上设置一个高于前一个单元格的单元格,然后看起来好像单元格从下往上堆叠.
但是,如果我将布局设置为另一个布局然后返回到原始布局,则会中断.就好像当前可见的单元格不会监听zIndex并放置在其他单元格的顶部.如果我在屏幕外滚动单元格然后重新打开它就在正确的位置.
有没有办法在现在(孩子)获得父VC的班级名称UIViewController
?我的'孩子'VC(推)有两个'父母' UIViewController
,所以我想知道哪一个是现在的父母?
ios ×8
swift ×7
accessory ×1
camera ×1
cgrectmake ×1
indicator ×1
int ×1
nsdata ×1
uiscrollview ×1
uitableview ×1
z-index ×1