How to get the center of the thumb image of UISlider

后端 未结 12 1780
挽巷
挽巷 2020-11-29 23:18

I\'m creating a custom UISlider to test out some interface ideas. Mostly based around making the thumb image larger.

I found out how to do that, <

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 23:58

    It's better to use -[UIView convertRect:fromView:] method instead. It's cleaner and easier without any complicated calculations:

    - (IBAction)scrub:(UISlider *)sender
    {
        CGRect _thumbRect = [sender thumbRectForBounds:sender.bounds
                                            trackRect:[sender trackRectForBounds:sender.bounds]
                                                value:sender.value];
        CGRect thumbRect = [self.view convertRect:_thumbRect fromView:sender];
    
        // Use the rect to display a popover (pre iOS 8 code)
        [self.popover dismissPopoverAnimated:NO];
        self.popover = [[UIPopoverController alloc] initWithContentViewController:[UIViewController new]];
        [self.popover presentPopoverFromRect:thumbRect inView:self.view
                    permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:YES];
    }
    

提交回复
热议问题