0

嘿伙计们,我迫切需要一些帮助,

我正在尝试将 UITextfield 中的数字解析为数学函数,然后将其解析为 UISlider,控制 UISlider。我已经在这里呆了 2 天,但是我无法从 UITextField 中获取数字来使 UISlider 移动,但它会自行移动。

谢谢您的帮助

这是一个片段:

 include <math.h>
    pragma mark - User Actions




 - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];

        CGFloat focal_length = [textField.text floatValue];
        CGFloat zoom =(2*atanh(4.592/(2*focal_length))*180/M_PI);
        //iPhone 5: 58.498 degrees (based upon a resolution of 3264x2448 pixels, a focal length of 4.1mm and a vertical chip size of 4.592mm)
        //2*atan(4.592/(2*4.28))*180/pi = 56.423 



     self.picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity,zoom, zoom);

        return YES;
    }



- (IBAction)focal_length:(UITextField *)sender
{
    CGFloat focal_length = [sender.text floatValue];
    CGFloat zoom =  1 + focal_length;
    //CGFloat zoom =  1 + 4*focal_length;
    self.picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity,zoom, zoom);
    _Slider.value = [sender.text floatValue];


}

- (IBAction)zoom:(id)sender{

UISlider *slider = (UISlider*)sender;
//CGFloat zoom =  1 + 4*slider.value;
CGFloat zoom = 1 + 4*slider.value;

// slider.value = [UITextField.text floatValue]; self.picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity,zoom, zoom); [sender resignFirstResponder]; }

4

1 回答 1

0

是否调用了您的 focus_length IBAction 或 textFieldShouldReturn 方法?将 NSLog 语句添加到两个方法的开头,或者在控制台中设置断点并确保它们被调用。

如果 textFieldShouldReturn 没有被调用,那么可能的罪魁祸首是您没有正确设置字段的委托。如果您的focus_length IBAction 方法没有被调用,原因可能是IB 中的IBAction 链接损坏。

于 2013-09-26T15:24:59.400 回答