gpt4 book ai didi

ios - 如何使用 UISwipeGestureRecognizer 为左/右滑动 View 设置动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:56 26 4
gpt4 key购买 nike

尝试在单 View 中滑动,它可以工作,但底部没有动画和页面指示器气泡

- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *swipeleft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(screenswipeleft)];
swipeleft.numberOfTouchesRequired=1;
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];

UISwipeGestureRecognizer *swiperight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(viewDidLoad)];
swiperight.numberOfTouchesRequired=1;
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swiperight];

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
[self.view addSubview:textField];
NSLog(@"move left");

}
-(void)screenswipeleft {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
[self.view addSubview:textField];
NSLog(@"move right");

}

最佳答案

假设您想要为 UITextField 设置动画。并且您的 UITextField 有一个 CGRect,起点为 x - 50,y - 100;

   @implementation myViewController{
UITextField *myTextField; //Declaring a textfield as an instance variable (global).
}


-(void)viewDidLoad{
myTextField = [UITextField alloc]initWithFrame:CGRectMake(50,100,100,50)];//adding memory and setting its initial position
//your other codes.
}
-(void)screenswipeleft {
[UIView animateWithDuration:3 animations:^{
myTextField.frame = CGRectMake:(-75,100,100,50); //setting the same textfield in a position of -75 only showing 1/4th of the textfield.
//this block animation would make the textfield animate from its starting position to this position in 3 seconds. (animateWithDuration:3 here u mention its duration).
}];
}

将相同的逻辑应用于其他人,您将获得所需的动画。

关于ios - 如何使用 UISwipeGestureRecognizer 为左/右滑动 View 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com