gpt4 book ai didi

ios - 如何在 uiscrollview 中点击后旋转图像?

转载 作者:行者123 更新时间:2023-11-29 04:03:10 25 4
gpt4 key购买 nike

- (void)configureView

{
lblwelcome.text=@"Welcome To Gallery World";
for (UIImageView *subview in self.view.subviews) {
[subview removeFromSuperview];
}

UIBarButtonItem *addAcc = [[UIBarButtonItem alloc]
initWithTitle:@"Zoom"
style:UIBarButtonItemStylePlain
target:self
action:@selector(zoomEnabled)];

UIBarButtonItem *delAcc = [[UIBarButtonItem alloc]
initWithTitle:@"Rotate"
style:UIBarButtonItemStylePlain
target:self
action:@selector(rotateEnabled)];

NSArray *arrBtns = [[NSArray alloc]initWithObjects:addAcc,delAcc, nil];
self.navigationItem.rightBarButtonItems = arrBtns;

categoryScrollX=30;
categoryScrollY=30;




[scr.delegate self];
scr.frame = self.view.frame;
for (UIImageView *subview in scr.subviews) {
[subview removeFromSuperview];
}
height = 200;
width = 400;
pos_y =0;
pos_x =0;
int idx=0;
CGFloat x=0;
switch (_itemNo) {
case 0:
for(int i=1;i<6;i++)
{//imageView.frame = CGRectMake(categoryScrollX, categoryScrollY, (self.view.frame.size.width/4)-25, self.view.frame.size.width/4-5);
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(categoryScrollX, categoryScrollY, (self.view.frame.size.width/4)-25, self.view.frame.size.width/4-5)];
[image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"e1%d.png",i]]];
[scr addSubview:image];
x+=320;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.delegate = self;
image.userInteractionEnabled = YES;
[image addGestureRecognizer:tapGesture];
// [image.layer setBorderColor: [[UIColor yellowColor] CGColor]];
// [image.layer setBorderWidth: 0.9];
// image.layer.MasksToBounds = false;
// image.layer.ShadowColor = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
// image.layer.ShadowOpacity = 1.0f;
// image.layer.ShadowOffset = CGSizeMake(0, 2.5f);
// image.clipsToBounds = NO;

CALayer* layer = [image layer];
[layer setBorderWidth:2.0f];
[image setContentMode:UIViewContentModeScaleAspectFit];
[layer setBorderColor:[UIColor whiteColor].CGColor];


scr.minimumZoomScale = scr.frame.size.width / imgview.frame.size.width;
scr.maximumZoomScale = 2.0;
[scr setZoomScale:scr.minimumZoomScale];
scrollPosition++;
currentIndex++;
if(scrollPosition>4)
{
categoryScrollY = categoryScrollY+self.view.frame.size.width/4+12;
scrollPosition=0;
currentIndex = currentIndex+scrollPosition;
categoryScrollX=30;
}
else
{
categoryScrollX= (categoryScrollX+self.view.frame.size.width/4)-6;
}


}

scr.pagingEnabled=YES;
scr.contentSize = CGSizeMake(320*5, 300);


_detailDescriptionLabel.text=@"Accessories";
self.title=@"Accessories";
[self.view addSubview:scr];

break;

......以下是使用上述方式使用不同图像的其他案例......

上面是我的配置 View ,我只是在 UiScrollview 中添加一些动态图像,并且我在每个图像上添加了点击手势......具有以下内容

-(void)handleSingleTap:(UITapGestureRecognizer *)rec{

for (UIImageView *subview in scr.subviews) {
[subview removeFromSuperview];
}

UIView *img = [rec view];
img.frame = self.view.frame;
[self.view addSubview:img];

}

现在我想要的是点击后我想为该图像提供旋转效果..我只是这个 Xcode 环境和 iOS 开发的初学者。

我是如何成功地在 uiscrollview 中显示图像的。但是经过 google 搜索,我找不到旋转图像的良好指导。所以任何人都可以帮我在 uiscrollview 中旋转 uiimageview 图像吗?图像被点击?

最佳答案

尝试这样,

-(IBAction)ButtonAction:(id)sender{
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 1;
fullRotation.repeatCount = 1;
[imageview.layer addAnimation:fullRotation forKey:@"360"];

}

选择一个按钮并为该按钮提供操作(调用此方法)。

关于ios - 如何在 uiscrollview 中点击后旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15612062/

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