gpt4 book ai didi

ios - 在 iOS 中为 uibutton 将 3 行动画化为箭头

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:38 25 4
gpt4 key购买 nike

有谁知道如何通过将 CGAfflineRotation 应用到 3 个 View 来将 3 条平行线动画化为右箭头,就像在导航菜单栏中发生的那样,以打开侧边菜单。

我真的需要这些方面的帮助,这样至少我可以有一个开始的想法。

这是尝试绘制它的样子:-

_______                  
_______ \
_______ to ___________\
/
/

任何想法或建议都会有所帮助。

最佳答案

如您所说,您应该使用CGAffineRotation。我给出了你想要的简单示例,所有内容都应该打包到适当的方法中, View 应该包含一些基本的 autolayouts/layoutFrames 等。我只是发布旋转的可能解决方案,快速写在viewDidAppear中,应该改变什么。

另一种选择是使用例如 firstView.layer.anchorPoint 并将其设置到适当的位置。

#define degreesToRadians(x) (M_PI * x / 180.0)

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

// let's create these 3 views as a lines
UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 1)];
[firstView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:firstView];
UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(50, 53, 50, 1)];
[secondView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:secondView];
UIView *thirdView = [[UIView alloc] initWithFrame:CGRectMake(50, 56, 50, 1)];
[thirdView setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:thirdView];

// now we can perform rotation, mind the degree and offsets in transform.
[UIView animateWithDuration:1 animations:^{
CGAffineTransform transform = CGAffineTransformMakeTranslation(24, 1);
transform = CGAffineTransformRotate(transform, degreesToRadians(45));
transform = CGAffineTransformTranslate(transform, -24, 1);
firstView.transform = transform;

transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(24, -1);
transform = CGAffineTransformRotate(transform, degreesToRadians(-45));
transform = CGAffineTransformTranslate(transform, -24, -1);
thirdView.transform = transform;
} completion:^(BOOL finished) {}];
}

关于ios - 在 iOS 中为 uibutton 将 3 行动画化为箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31131492/

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