3我有一个被触摸操纵的图像.
让我们说它是一个指向箭头的图像.在它旋转180度后,箭头现在指向下方,我想重置CGAffineTransform属性,以便它现在认为它转回0度.
我想要这个,因为我必须翻译,旋转,缩放等,无论图像的角度是0还是180.
提前致谢.
EDITED Ater 5回复:
嗯,我不确定这些答案是否符合我的要求.我为不清楚而道歉.
为了防止上述问题和其他问题,我希望在旋转180后重置所有内容.例如,一旦图像变为180度,CGAffineTransform属性就知道它已经转为180%.我想在那个时候重置这些属性,所以CGAffineTransform认为它变为0度而不是180度,尽管图像是视觉上倒置的.我希望这种情况在没有任何视觉变化的情况下发生,一旦旋转到180度.
希望这更清楚......
我想做什么:
由父视图控制器管理的父视图不应该旋转.
由子视图控制器管理的子视图应该旋转到所有方向.
我试过的:
ParentViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
}
override func shouldAutorotate() -> Bool {
return true
}
fun addChildViewController() {
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
self.childViewController = storyBoard("Child View Controller") as? ChildViewController
self .addChildViewController(self.childViewController!)
self.childViewController! .didMoveToParentViewController(self)
self.view .addSubview(self.childViewController!.view)
self.childViewController!.view.frame = CGRectMake (40, 200, 400, 250)
}
Run Code Online (Sandbox Code Playgroud)
ChildViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .All
}
override func shouldAutorotate() -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
Xcode部署信息中支持的方向设置为全部四个.
我得到了什么:
没有View的旋转.如果我将父级的旋转设置为all,则所有视图一起旋转.所以它是全有或全无. …
xcode uiviewcontroller landscape-portrait childviewcontroller swift
Simliar到iOS Photos App,用户通过捏合放大和缩小图像:
UIView> UIScrollView> UIImageView> UIImage
最初,我遇到了缩放比例1以下的问题:图像偏离中心.我通过这样做得到了解决方法:
func scrollViewDidZoom(scrollView: UIScrollView) {
let offsetX = max((scrollView.bounds.width - scrollView.contentSize.width) * 0.5, 0)
let offsetY = max((scrollView.bounds.height - scrollView.contentSize.height) * 0.5, 0)
scrollView.contentInset = UIEdgeInsetsMake(offsetY, offsetX, 0, 0)
}
Run Code Online (Sandbox Code Playgroud)
这在缩小时效果很好.
UIImage内容模式是aspectFit
当我ZOOM IN时,当zoomScale大于1时,滚动视图插图需要拥抱滚动视图包含的UIImage的周围环境.这消除了UIImage周围的死空间.IE,照片应用程序通过捏或双击放大.
func scrollViewDidZoom(scrollView: UIScrollView) {
if scrollView.zoomScale > 1 {
let imageScale = (self.imageView.bounds.width/self.imageView.image!.size.width)
let imageWidth = self.imageView.image!.size.width * imageScale
let imageHeight = self.imageView.image!.size.height * imageScale
scrollView.contentInset = UIEdgeInsetsMake(((scrollView.frame.height - imageHeight) * 0.5), (scrollView.frame.width - imageWidth) …
Run Code Online (Sandbox Code Playgroud) 问题:
在调用状态栏消失后,模态呈现的视图控制器不会向上移动,在顶部留下20px空/透明空间.
正常:没有问题
在电话:没有问题
在呼叫消失后:
在顶部留下20px高的空/透明空间,露出下面的橙色视图.但是,状态栏仍然存在于透明区域上方.导航栏还为状态栏留出空间,它的位置只有20px太低.
我试着听App代表:
willChangeStatusBarFrame
didChangeStatusBarFrame
Run Code Online (Sandbox Code Playgroud)
还可以查看基于控制器的通知:
UIApplicationWillChangeStatusBarFrame
UIApplicationDidChangeStatusBarFrame
Run Code Online (Sandbox Code Playgroud)
当我为所有上述四种方法记录呈现视图的帧时,帧始终位于(y:0)原点.
查看控制器自定义模式演示
let storyboard = UIStoryboard(name: "StoryBoard1", bundle: nil)
self.modalVC = storyboard.instantiateViewController(withIdentifier: "My Modal View Controller") as? MyModalViewController
self.modalVC!.transitioningDelegate = self
self.modalVC.modalPresentationStyle = .custom
self.modalVC.modalPresentationCapturesStatusBarAppearance = true;
self.present(self.modalVC!, animated: true, completion: nil)
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)
toViewController!.view.transform = CGAffineTransform(scaleX: 0.001, …
Run Code Online (Sandbox Code Playgroud) 在Apple的Photo's App上,如果在滚动到任意偏移的同时旋转设备,预先在中心的相同单元将在旋转后终止于中心.
我试图用UICollectionView实现相同的行为.' indexPathsForVisibleItems '似乎是这样做的方式....
以下代码提供了旋转之间的平滑操作,但中心项计算似乎是关闭的:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.collectionView?.collectionViewLayout.invalidateLayout()
let middleItem = (self.collectionView?.indexPathsForVisibleItems.count / 2) - 1
let indexPath = self.collectionView?.indexPathsForVisibleItems[middleItem]
coordinator.animate(alongsideTransition: { ctx in
self.collectionView?.layoutIfNeeded()
self.collectionView?.scrollToItem(at: indexPath!, at: .centeredVertically, animated: false)
}, completion: { _ in
})
}
Run Code Online (Sandbox Code Playgroud)
uiscrollview ios uicollectionview uicollectionviewlayout swift
我正在使用UIViewControllerAnimatedTransitioning
protocol
附加UIViewPropertyAnimator
平移来关闭视图控制器
extension SecondViewController : UIViewControllerAnimatedTransitioning {
func interruptibleAnimator(using ctx: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating {
if self.animator != nil {
return self.animator!
}
let containerView = ctx.containerView
let toVC = ctx.viewController(forKey: .to) as! FirstViewController
let fromVC = ctx.viewController(forKey: .from) as! SecondViewController
containerView.insertSubview(toVC.view, belowSubview: fromVC.view)
self.animator = UIViewPropertyAnimator(duration: transitionDuration(using: ctx),
curve: .easeOut, animations: {
self.fromVC.view.transform = CGAffineTransform(scale: 0.5)
})
self.animator.isInterruptible = true
self.animator.isUserInteractionEnabled = true
self.animator.isManualHitTestingEnabled = true
self.animator.addCompletion { position in
switch position {
case .end: …
Run Code Online (Sandbox Code Playgroud) 我有以下在iOS 11上正常工作:
let ciContext = CIContext(options: [kCIContextWorkingFormat : kCIFormatRGBAh])
var outputImage : CIImage
let mainImage = CIImage(data: jpegData)
let disparityImage = CIImage(data: jpegData, options: [kCIImageAuxiliaryDisparity : true])
let filter = CIFilter(name: "CIDepthBlurEffect",
withInputParameters: [kCIInputImageKey : mainImage!,
kCIInputDisparityImageKey: disparityImage!])
outputImage = filter!.outputImage!
Run Code Online (Sandbox Code Playgroud)
在iOS 12之前,Rendtition很好,一切都模糊了.这是迄今为止的每个测试版.整个图像模糊不清.
我找不到任何API更改说明,也CIDepthBlurEffect
没有记录开始.
控制台中的Xcode/iOS 8/AVFoundation相关错误:
error in __connection_block_invoke_2: Connection interrupted
Run Code Online (Sandbox Code Playgroud)
我只是将AVCaptureVideoDataOutput添加到Apple的示例应用程序'AVCamManualUsingtheManualCaptureAPI'
我添加的是:
// CoreImage wants BGRA pixel format
NSDictionary *outputSettings = @{ (id)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInteger:kCVPixelFormatType_32BGRA]};
// create and configure video data output
AVCaptureVideoDataOutput *videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
videoDataOutput.videoSettings = outputSettings;
videoDataOutput.alwaysDiscardsLateVideoFrames = YES;
[videoDataOutput setSampleBufferDelegate:self queue:sessionQueue];
Run Code Online (Sandbox Code Playgroud)
上面插入到示例项目的代码段:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.recordButton.layer.cornerRadius = self.stillButton.layer.cornerRadius = self.cameraButton.layer.cornerRadius = 4;
self.recordButton.clipsToBounds = self.stillButton.clipsToBounds = self.cameraButton.clipsToBounds = YES;
// Create the AVCaptureSession
AVCaptureSession *session = [[AVCaptureSession alloc] init]; …
Run Code Online (Sandbox Code Playgroud) 在GM Xcode(和iOS 11)之前运行良好.现在我收到这些错误:
Apple Mach-O Linker (ld) Error Group
"__T0So20AVCapturePhotoOutputC12AVFoundation01_abC16SwiftNativeTypesACWP", referenced from:
xxxxxxxxxx
"__T012AVFoundation37_AVCapturePhotoOutputSwiftNativeTypesPAAE012availableRawc11PixelFormatG0SaySo8NSNumberCGfg", referenced from:
xxxxxxxxx
" "__T0So22AVCapturePhotoSettingsC12AVFoundation01_abC16SwiftNativeTypesACWP", referenced from:
xxxxxxxxxx
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
它指向的一些行是:
photoSettings = AVCapturePhotoSettings(rawPixelFormatType: OSType(self.photoOutput.availableRawPhotoPixelFormatTypes.first!))
photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: photoSettings.availablePreviewPhotoPixelFormatTypes.first!.uint32Value,
kCVPixelBufferWidthKey as String: 3024, kCVPixelBufferHeightKey as String: 3024]
Run Code Online (Sandbox Code Playgroud)
也:
let rawFormat = self.photoOutput.availableRawPhotoPixelFormatTypes.first!.uint32Value
photoSettings = AVCapturePhotoSettings(rawPixelFormatType: OSType(rawFormat),
processedFormat: [AVVideoCodecKey : AVVideoCodecJPEG,
AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] …
Run Code Online (Sandbox Code Playgroud) ios ×6
swift ×6
xcode ×6
avfoundation ×2
uiscrollview ×2
cifilter ×1
core-image ×1
depth ×1
in-call ×1
ios11 ×1
iphone ×1
macos ×1
nstouchbar ×1
reset ×1
rotation ×1
statusbar ×1
swift3 ×1
uiedgeinsets ×1
zoom ×1