Ipad 如何旋转CollectionView单元格以使项目保持居中?
我在iPad应用程序中设置了UIcollectionView,每次显示一张照片。当我从横向图像旋转图像时,我希望调整图像大小,以便旋转开始时显示的图像在纵向旋转结束时居中。调整大小是可行的,但旋转结束时会显示两个项目之间的边界。我不知道如何保持图像居中,因为我想 也许“居中”是错误的说法,也许我的意思是将图像的左侧保持在帧的左侧。作为iOS和Swift的新手,我的部分问题是我甚至不知道如何正确地描述(没有双关语) 显示了问题以及我正在努力实现的目标 有可能做我想做的事情吗?如果有,最好的方法是什么 以下是迄今为止的代码:Ipad 如何旋转CollectionView单元格以使项目保持居中?,ipad,uicollectionview,ios9,uicollectionviewcell,Ipad,Uicollectionview,Ios9,Uicollectionviewcell,我在iPad应用程序中设置了UIcollectionView,每次显示一张照片。当我从横向图像旋转图像时,我希望调整图像大小,以便旋转开始时显示的图像在纵向旋转结束时居中。调整大小是可行的,但旋转结束时会显示两个项目之间的边界。我不知道如何保持图像居中,因为我想 也许“居中”是错误的说法,也许我的意思是将图像的左侧保持在帧的左侧。作为iOS和Swift的新手,我的部分问题是我甚至不知道如何正确地描述(没有双关语) 显示了问题以及我正在努力实现的目标 有可能做我想做的事情吗?如果有,最好的方法是什
class PhotoCollectionViewController: UICollectionViewController {
var businessData = [BData]()
var theBusiness:BData?
var currentDevice: UIDevice = UIDevice.currentDevice()
override func viewDidLoad() {
super.viewDidLoad()
definesPresentationContext = true
businessData = appData.getBusinessData()
}
override func numberOfSectionsInCollectionView(collectionView:
UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
return businessData.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("photoCell", forIndexPath: indexPath) as! PhotoCell
// Configure the cell
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docsDir = dirPaths[0]
let theBusinessPhoto = docsDir+"/bPhotos/"+businessData[indexPath.row].bPhotoFilename!
cell.splashPhoto.image = UIImage(contentsOfFile: theBusinessPhoto)
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if let cell = collectionView.cellForItemAtIndexPath(indexPath) {
performSegueWithIdentifier("gotoBusinessInfo", sender: cell)
} else {
// Error.
}
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
showViewSettings()
self.collectionView!.collectionViewLayout.invalidateLayout()
view.layoutIfNeeded()
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if (currentDevice.orientation.isLandscape){
return CGSizeMake(1024, 704)
} else {
return CGSizeMake(768, 528)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
assert(sender as? UICollectionViewCell != nil, "sender is not a collection view")
if let indexPath = self.collectionView?.indexPathForCell(sender as! UICollectionViewCell) {
if segue.identifier == "gotoBusinessInfo" {
let businessDetailVC = segue.destinationViewController as! BusinessInfoVC
businessDetailVC.businessData = businessData[indexPath.row]
}
} else {
// Error.
}
}
func showViewSettings(){
print ("Device......: " + UIDevice.currentDevice().name)
print ("Model.......: " + UIDevice.currentDevice().localizedModel)
print ("Orientation.: " + String(UIDevice.currentDevice().orientation.rawValue))
print ("View width..: " + String(self.view.bounds.size.width))
print ("View height.: " + String(self.view.bounds.size.height))
print ("S.bar height: " + String(UIApplication.sharedApplication().statusBarFrame.height))
print ("S.bar hidden: " + String(UIApplication.sharedApplication().statusBarHidden))
print ("N.bar height: " + String(self.navigationController?.navigationBar.frame.height))
}
}
showViewSettings()只是一个调试辅助工具。我认为这个问题的答案(经过多次搜索后找到)接近我想要的,但我无法从Objective CI翻译。我认为这个问题的答案(经过多次搜索后找到)接近我想要的,但我无法从Objective-C翻译