【问题标题】:How to rotate image and arrow line from a fixed center point如何从固定中心点旋转图像和箭头线
【发布时间】:2015-11-04 06:11:12
【问题描述】:

在我的应用程序中,我有一个固定大小的按钮/中心点,我想旋转箭头线,当我触摸/向上/向下滚动时,这个附加的图像也会旋转。 我在这个演示中做了一个演示,我使用 icarousel 类只滚动图像。 但我不能同时滚动箭头和图像滚动。 请帮助我如何实现这一点。

我的仅使用 icarousel 进行图像滚动的代码在这里..

  - (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex: (NSInteger)index reusingView:(UIView *)view
{
UIView *viewFor;
UIImageView *itemView;
if (view==nil) {

    viewFor=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    itemView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 45, 120, 120)];
    [itemView.layer setCornerRadius:itemView.frame.size.width/2];
    [itemView setClipsToBounds:YES];
    [viewFor addSubview:itemView];

        StikImage=[[UIImageView alloc]initWithFrame:CGRectMake(-140, 95, 140, 20)];
   StikImage.backgroundColor=[UIColor whiteColor];
   [viewFor addSubview:StikImage];

  }
  else
  {
    viewFor=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    itemView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 45, 120, 120)];
    [itemView.layer setCornerRadius:itemView.frame.size.width/2];
    [itemView setClipsToBounds:YES];
    [viewFor addSubview:itemView];

        StikImage=[[UIImageView alloc]initWithFrame:CGRectMake(-140, 95, 140, 20)];
         StikImage.backgroundColor=[UIColor whiteColor];
        [viewFor addSubview:StikImage];

  }
   itemView.image=[images objectAtIndex:index];
return viewFor;
 }

这是我用于转换图像的自定义类型 icrousel 方法

- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform {

const CGFloat centerItemZoom = 1.6;
const CGFloat centerItemSpacing = 1.2;
const CGFloat centerItemYOffset = 100;
CGFloat spacing = [self carousel:carousel valueForOption:iCarouselOptionSpacing withDefault:1.3f];
CGFloat absClampedOffset = MIN(2.5, fabs(offset));
CGFloat clampedOffset = MIN(1.0, MAX(-1.0, offset));
CGFloat scaleFactor = 1.0 + absClampedOffset * (1.2/centerItemZoom - 1.0);
CGFloat yoffset = (1.0f - absClampedOffset) * centerItemYOffset;
offset = (scaleFactor * offset + scaleFactor * (centerItemSpacing - 1.0) * clampedOffset) * carousel.itemWidth * spacing;



if (carousel.vertical)
{
    transform = CATransform3DTranslate(transform, yoffset, offset, -absClampedOffset);

}
else
{
    transform = CATransform3DTranslate(transform, offset, yoffset, -absClampedOffset);
}

transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 5.0f);
  return transform;
 }

【问题讨论】:

    标签: iphone xcode image-rotation icarousel


    【解决方案1】:

    使用下面的代码来旋转图像视图

    imageview.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
    

    您可以使用您想要的度数大小,例如 180、90、240、270...,取决于您的要求“触摸/向上/向下”

    【讨论】:

    • 首先感谢@iSara 的回答,但我如何设置 y 偏移量和度数,以针对图像向上/向下滚动箭头/线。
    • @RAMA: 你能在滚动视图委托方法中使用上面的代码吗?
    • ..我不能...我使用 iCarousel 视图在我的代码中实现了这种类型,仅适用于图像,但现在我想添加这些箭头/线与图像..这些箭头也以相同角度同时旋转图像我怎么能做到这一点..请帮助我..
    猜你喜欢
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多