"UIPickerView" tugmasini bosgandan keyin uni qanday qilib jonlantira olaman?

Men tugmachani bosgandan so'ng UIPickerView-ni jonlantirmoqchiman. Men UIPickerView-ni viewDidLoad-da yashirish uchun kodladim va bir tugmani bosganimdan keyin maxfiy emasman, lekin ModalViewController-ni sukut bo'yicha animatsiya qiladigan kabi jonlantirmaydi. Men faqat UIPickerView-ni odatiy ravishda ModalViewController animatsiyalari kabi animatsiya qilishni xohlayman.

Saytda va veb-saytda tadqiqot qildim, lekin buni to'g'ri deb bo'lmaydi.

Mana mening kodim:

#pragma mark - Picker View 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 4;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    timersArray = [[NSMutableArray alloc] init];
    [timersArray addObject:@"No timer"];
    [timersArray addObject:@"15 seconds"];
    [timersArray addObject:@"30 seconds"];
    [timersArray addObject:@"60 seconds"];

    return [timersArray objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if ([[timersArray objectAtIndex:row] isEqual:@"No timer"])
    {
        timerIndication.text = @"No timer selected";
        timersPickerView.hidden = YES;
       //Animation code to dismiss picker should go here
    }
    else if ([[timersArray objectAtIndex:row] isEqual:@"15 seconds"])
    {
        timerIndication.text = @"15 seconds selected";
        timersPickerView.hidden = YES;
       //Animation code to dismiss picker should go here
    }
    else if ([[timersArray objectAtIndex:row] isEqual:@"30 seconds"])
    {
        timerIndication.text = @"30 seconds selected";
        timersPickerView.hidden = YES;
       //Animation code to dismiss picker should go here
    }
    else if ([[timersArray objectAtIndex:row] isEqual:@"60 seconds"])
    {
        timerIndication.text = @"60 seconds selected";
        timersPickerView.hidden = YES;
       //Animation code to dismiss picker should go here
    }
}

#pragma mark - Delay method

// This is where Send button should be enabled
- (IBAction)selectTimer
{
    timersPickerView.hidden = NO;
   //Animation code to present picker view should go here
}
6

5 javoblar

Tugmani bosgandan so'ng tanlovchini ko'rish uchun quyidagi koddan foydalanishingiz mumkin:

-(IBAction)button:(id)sender
{

   [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.6];
    CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 200);
    PickerView.transform = transfrom;
    PickerView.alpha = PickerView.alpha * (-1) + 1;
    [UIView commitAnimations];

}

ViewDidLoad usulida quyidagi kodni qo'shishni unutmang

PickerView.alpha = 0;    
[self.view addSubview:PickerView];

Nima qilsa bo'ladi, bu tanlovchining ko'rinishi ekranning ustki qismidan 1-sekin urilib tushiradi va tanlovchining ko'rinishi yo'qoladi, siz faqat tugmani yana bosishingiz mumkin. Keyingi tugmani bosgan holda, tanlovchining ko'rinishi ko'rinadi va yo'qoladi. yordam beradi va ishlaydi :)

10
qo'shib qo'ydi
Katta javob :).
qo'shib qo'ydi muallif androniennn, manba
@androniennn javobimga xursand bo'ldim va komplemaning uchun rahmat :)
qo'shib qo'ydi muallif Eshwar Chaitanya, manba

Bir viewcontroller yaratishingiz va UIPickerView-ni tekshirgich ichida qo'shishingiz va undan keyin foydalanishingiz mumkin:

[self presentModalViewController: viewControllerWithPickerView animatsiya: Ha];

yoki siz UIPickerView-ni 480.0 yoki undan kattaroq qilib ekrandan kattaroq y qiymatiga qo'sha olasiz va UIPickerView-ni shu joydan ekranda ko'rinadigan joyga ko'chirish uchun ishlatasiz, bu ModalViewController animatsiyasini taqlid qiladi.

5
qo'shib qo'ydi
Rahmat. Buning o'rniga, bu vaqtinchalik hal qiladi. ;)
qo'shib qo'ydi muallif jaytrixz, manba
Modalviewcontroller'imdagi pickerview bilan yuklayotganimda ko'rinishni yaratishda ham vaqtinchalik echim bormi?
qo'shib qo'ydi muallif jaytrixz, manba
Yashirin UIView qora fon va 0,5 alfa bilan foydalanishingiz mumkin va UIPickerView animatsiyasini tinglang, u tugaganidan so'ng siz UIViewni ko'rsatasiz. Ushbu UIView har bir narsa ustida joylashtirilishi kerak, lekin UIPickerView.
qo'shib qo'ydi muallif Paul N, manba

Tanlovchining ko'rinishini animatsiya qilish uchun quyidagi funktsiyadan foydalanishingiz mumkin.

-(void)hideShowPickerView {

if (!isPickerDisplay) {
    [UIView animateWithDuration:0.25 animations:^{
        CGRect temp = self.categoryPicker.frame;
        temp.origin.y = self.view.frame.size.height - self.categoryPicker.frame.size.height;
        self.categoryPicker.frame = temp;
    } completion:^(BOOL finished) {
        NSLog(@"picker displayed");
        isPickerDisplay = YES;
    }];
}else {
    [UIView animateWithDuration:0.25 animations:^{
        CGRect temp = self.categoryPicker.frame;
        temp.origin.y = self.view.frame.size.height;
        self.categoryPicker.frame = temp;
    } completion:^(BOOL finished) {
        NSLog(@"picker hide");
        isPickerDisplay = NO;
    }];
}

}

IsPickerDisplay-ni BOOL deb belgilang va uni quyidagicha ViewDidLoad-ga ishga tushiring -

isPickerDisplay = YES;
[self hideShowPickerView];

Bu UIPickerView funksiyasini yashirish va ko'rsatishni boshqaradi.

2
qo'shib qo'ydi

Swift 3 biznes

Men @EshwarChaitanya bilan rozilik bildiraman, alfa xususiyatini jonlantiradi va bu to'g'ri ishlatishdir.

override func viewDidLoad() {
    super.viewDidLoad()

    timersPickerView.alpha = 0
}

@IBAction func selectTimer() {
    UIView.animate(withDuration: 0.3, animations: {
        self.timersPickerView.alpha = 1
    })
}

Men buni qanday qilib yashirishni xohlayotganingizdan amin emasman, shuning uchun uni sizni tark etaman.

1
qo'shib qo'ydi

Tugmasini bosganingizda, harakatni [self.view addSubVuew: yourPickerView] qiling; . Ishsizmi?

0
qo'shib qo'ydi
Bunday hol emas. Tugmani bosganimda, faqat ViewerDidLoad-da sukut saqlanganidan beri PickerView paydo bo'ladi. PickerView-da bir qatorni tanlagach, yana yashiradi.
qo'shib qo'ydi muallif jaytrixz, manba