Slide finger from button to another button in iPhone
I am beginner in iPhone development. How can we drag from one button to another button us开发者_如何学编程ing finger? I used touchMoved
but it's not working. Is it possible?
Thank you.
Try this -
![- (void)create_Custom_UISlider
{
CGRect frame = CGRectMake(10.0, 50.0, 300, 52.0);
CGRect thumb = CGRectMake(0.0, 0.0, 71.0, 47.0);
customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"customTrack.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"customTrack.png"]
stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"customThumb_off.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
[customSlider thumbRectForBounds: thumb trackRect: frame value: customSlider.value];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 1.0;
customSlider.continuous = YES;
customSlider.value = 0.0;
}
- (void) sliderAction: (UISlider *) sender
{
if (customSlider.value != 1.0) //if the value is not the max, slide this bad boy back to zero
{
[sender setValue: 0 animated: YES];
}
else {
if (customSlider.value == 1.0) //if the value is max, slide this bad boy back to zero and execute code
{
[sender setValue: 0 animated: NO];
}
// the rest of your code here.
}
}][1]
Also have a look on this Question - iPhone "slide to unlock" animation
Yes it possible. first you put this method :..........
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
btn addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
}
and
- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event
{
scroll.frame=CGRectMake(self.scroll.frame.origin.x, self.scroll.frame.origin.y, self.scroll.frame.size.width+1800, self.scroll.frame.size.height);
scroll.contentSize=CGSizeMake(2000,1200);
scroll.backgroundColor=[UIColor clearColor];
UITouch *touch = [[event touchesForView:button] anyObject];
NSLog(@"%d",button.frame.origin.x);
CGPoint previousLocation = [touch previousLocationInView:button];
CGPoint location = [touch locationInView:button];
CGFloat delta_x = location.x - previousLocation.x;
CGFloat delta_y = location.y - previousLocation.y;
button.center = CGPointMake(button.center.x + delta_x,
button.center.y + delta_y);
}
精彩评论