1

I tried to do a bottom up UIPickerView component, first i created a container view, other than my actual view, then i added a picker view to container view. I set this view's y position to 1690. If button pressed it'll move up with animation like that.

func createPicker(sender: UIButton)
{
    if(isPickerViewOpened == false){
    pickerView.reloadAllComponents()
    shadowImageView.alpha = 0.6
    UIView.animateWithDuration(0.5, animations: { () -> Void in
        self.pickerContainer.center = CGPointMake(self.pickerContainer.center.x, self.pickerContainer.center.y - 1000)
    })
    isPickerViewOpened = true
    }

}

But when the DidSelectRow function worked, that view goes back to its original position.

My DidSelectRow function:

func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{


    urunCesitButton.setTitle("\(urunCesitAd[row])", forState: .Normal)
    urunKodu = urunCesitKod[row]
    urunAd = urunCesitAd[row]
    urunFiyat = urunCesitFiyat[row]
    urunAdLabel.text = urunAd
    urunFiyatLabel.text = "\(urunFiyat) TL"
    shadowImageView.alpha = 0
    scrollerView.userInteractionEnabled = true
    decreaseButtonOutlet.userInteractionEnabled = true
    urunAdet.userInteractionEnabled = true
    increaseButtonOutlet.userInteractionEnabled = true

}

I tried endEditing or resignFirstResponder() to solved that but it doesn't work. Someone else also asked this question but he didn't get an answer.

Mert Serin
  • 289
  • 6
  • 20
  • 1
    Your problem is most likely down to constraints associated with the pickerContainer. Did you create the picker with the offset in interface builder? When you select, the layout is probably being redone and it is moving it back to its default position. You might be best to add a constraint for the left and top position and then animate the constraint. This will ensure its stays where the constraints define it to be. You can create IBOutlets for the constraints by CTRL dragging from the constraint into your .h file. Then animate the constant value of each constraint. – Rory McKinnel Apr 13 '15 at 12:46
  • See http://stackoverflow.com/questions/12622424/how-do-i-animate-constraint-changes – Rory McKinnel Apr 13 '15 at 12:47
  • Great, I posted it as an answer if you could kindly accept it. – Rory McKinnel Apr 13 '15 at 13:18

2 Answers2

2

Your problem is most likely down to constraints associated with the pickerContainer. Did you create the picker with the offset in interface builder? When you select, the layout is probably being redone and it is moving it back to its default position. You might be best to add a constraint for the left and top position and then animate the constraint. This will ensure its stays where the constraints define it to be. You can create IBOutlets for the constraints by CTRL dragging from the constraint into your .h file. Then animate the constant value of each constraint.

See How do I animate constraint changes?

Community
  • 1
  • 1
Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
0

I checked the "Clip to bounds" option in the utility window - attributes and that saved the picker from disappering

itzuvid
  • 81
  • 1
  • 7