2017-03-19 11 views
0

私は2つのオブジェクトを持っています。最初のものはImageViewで、もう1つはTextViewです。swift 3とUIImageviewの場合

これらのオブジェクトに対してアニメーションを行いました。ユーザーが画像をクリックすると、textViewが展開されてテキスト全体が表示されます。しかし、textViewが展開されると、imageViewはイメージの奇妙なサイズを表示します。スーパーズームインのように見えます。 UICollectionViewController {

var imageViewArray = [UIImage]() 
var textArray = [String]() 




override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    imageViewArray = [#imageLiteral(resourceName: "a"),#imageLiteral(resourceName: "b"),#imageLiteral(resourceName: "c")] 


    textArray = [ 
     // firststory Starts 
     "firststory", 

       // SecondStory starts 
       "Hello", 

       // thirdStors starts 
       "thirdStory"] 

} 




override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return imageViewArray.count 

} 


override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as UICollectionViewCell 

    // give the objects their IDs 

    let imageView = cell.viewWithTag(1) as! UIImageView 
    imageView.image = imageViewArray[indexPath.row] 


    let textView = cell.viewWithTag(2) as! UITextView 
    textView.isScrollEnabled = false 
    textView.text = textArray[indexPath.row] 




    let backButton = cell.viewWithTag(3) as! UIButton 
    backButton.isHidden = true 



    return cell 
} 


// adding some animation to the cells 

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    let cell = collectionView.cellForItem(at: indexPath) 

    cell?.superview?.bringSubview(toFront: cell!) 



    UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({ 



     cell?.frame = collectionView.bounds 
     collectionView.isScrollEnabled = false 

     let textView = cell!.viewWithTag(2) as! UITextView 
     textView.isScrollEnabled = false 


     // some codes to help back button to work ! 
     let backButton = cell!.viewWithTag(3) as! UIButton 
     backButton.isHidden = false 
     backButton.addTarget(self, action: #selector(CollectionViewController.backbtnAction), for: UIControlEvents.touchUpInside) 



    }), completion: nil) 



} 


// back button 

func backbtnAction() { 

    let indexPath = collectionView?.indexPathsForSelectedItems 
    collectionView?.isScrollEnabled = true 
    collectionView?.reloadItems(at: indexPath!) 
} 

}

+0

あなたの質問は何ですか?何を達成したいのかははっきりしていません。 – Jurasic

答えて

0

はImageViewの内容モードが.scaleAspectFitかに設定されていることを確認します

This picture to make it clear

、ここでは私のコード

import UIKit 

クラスCollectionViewControllerをです。 scaleAspectFill

関連する問題