点击uiscrollview后如何旋转图像?

时间:2013-03-25 09:57:48

标签: ios uiscrollview rotation xcode4.5

- (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;

.....以其他方式跟随上述方式使用不同的图像......

以上是我的配置视图,我只是在UiScrollview中添加了一些动态图像,我在每个图像上添加了tap guest ....以下

-(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环境以及i​​OS开发的初学者。

一些我如何成功地在uiscrollview中显示图像..但是在google搜索之后我找不到旋转图像的良好指导。所以任何人都可以帮助我在uiscrollview之后给uiimageview图像旋转图像被点击?

2 个答案:

答案 0 :(得分:1)

尝试这样,

-(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"];

}

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

答案 1 :(得分:0)

您可以使用以下代码旋转imageView:

imageView.transform = CGAffineTransformMakeRotation(angle);