使用 UISwipeGestureRecognizer 滑动视图

发布于 2024-11-28 05:24:25 字数 500 浏览 1 评论 0原文

大家好,我想问一些事情,我尝试使用标签在视图之间滑动,但我不知道问题所在?

UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];


-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender{
      ThirdQPage* y=[[ThirdQPage alloc]init];
[self.view.superview addSubview:[y view]];
[self.view removeFromSuperview];}

hi all freind i want ask somthing, i try use label to swipe between views but i cant know the problem?

UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];


-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender{
      ThirdQPage* y=[[ThirdQPage alloc]init];
[self.view.superview addSubview:[y view]];
[self.view removeFromSuperview];}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

触ぅ动初心 2024-12-05 05:24:25

您可以这样做 -

- (void)hideView:(NSTimer *)timer
{    
    UIView *currentView = (UIView *)[timer userInfo];
    [currentView addSubview:self.yourNewView];
    return;
}

-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
{
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                           forView:yourCurrentView cache:YES];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1];
    [NSTimer scheduledTimerWithTimeInterval:0.5 
                                     target:self 
                                   selector:@selector(hideView:) 
                                   userInfo:yourCurrentView 
                                    repeats:NO];
    [UIView commitAnimations];
}

您可以使用相同的逻辑从 newView 滑回 oldView

You could do this -

- (void)hideView:(NSTimer *)timer
{    
    UIView *currentView = (UIView *)[timer userInfo];
    [currentView addSubview:self.yourNewView];
    return;
}

-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
{
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                           forView:yourCurrentView cache:YES];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1];
    [NSTimer scheduledTimerWithTimeInterval:0.5 
                                     target:self 
                                   selector:@selector(hideView:) 
                                   userInfo:yourCurrentView 
                                    repeats:NO];
    [UIView commitAnimations];
}

You can use the same logic to swipe back from your newView to oldView.

獨角戲 2024-12-05 05:24:25

设置label.userInteractionEnabled = YESUILabel 的默认值为 NO,因此所有触摸都会被忽略。

userInteractionEnabled 一个布尔值,用于确定用户是否
事件将被忽略并从事件队列中删除。

@property(非原子,getter=isUserInteractionEnabled) BOOL
用户交互启用

讨论该属性继承自
UIView父类。这个类改变了这个的默认值
属性为NO。

Set label.userInteractionEnabled = YES. The default value for UILabel is NO, therefore all touches are ignored.

userInteractionEnabled A Boolean value that determines whether user
events are ignored and removed from the event queue.

@property(nonatomic, getter=isUserInteractionEnabled) BOOL
userInteractionEnabled

Discussion This property is inherited from the
UIView parent class. This class changes the default value of this
property to NO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文