菜鸟教程小白 发表于 2022-12-12 13:22:33

ios - ScrollView 分页,图像略微向左或向右显示(开始/结束)


                                            <p><p>我尝试创建一个水平页面 slider ,就像您在大多数问答游戏中看到的那样。</p>

<p>基本上每个页面都有和图像/按钮在屏幕右侧略微显示,
表示还有更多页面。</p>

<p>在最后一页上,用户应该不会看到右侧的图像,而是左侧的图像,因为它是最后一页。</p>

<p>所以在图像之间显示左右。</p>

<p>有没有办法通过检查器或仅以编程方式执行此操作?</p>

<p>我尝试了这两种方法,结果出现了一些奇怪的副作用,它会弹回图像的中心位置。</p>

<p>见下图:</p>

<p> <a href="https://plus.google.com/u/0/101813614111502094997/posts" rel="noreferrer noopener nofollow">https://plus.google.com/u/0/101813614111502094997/posts</a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用此代码</p>

<p>在.h文件中使用</p>

<pre><code>@property (weak, nonatomic) IBOutlet UIScrollView *imageScrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
</code></pre>

<p>在 .m 类中</p>

<pre><code>#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) &lt; DBL_EPSILON )

-(void)viewDidAppear:(BOOL)animated{
         ;

      NSArray *viewsToRemove = ;
      for (UIView *subviewElement in viewsToRemove) {
            ;
      }

      UIImageView *img1= [ initWithFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?370:284)];
      img1.image=;
      ;

      UIImageView *img2= [ initWithFrame:CGRectMake(320, 0, 320, IS_IPHONE_5?370:284)];
      img2.image=;
      ;

      UIImageView *img3= [ initWithFrame:CGRectMake(640, 0, 320, IS_IPHONE_5?370:284)];
      img3.image=;
      ;

      ;
      ;
      ;

    }

    - (void)viewDidLayoutSubviews
    {
      self.imageScrollView.contentSize= CGSizeMake((imageScrollView.frame.size.width*3) , imageScrollView.frame.size.height);

    }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios -ScrollView 分页,图像略微向左或向右显示(开始/结束),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18080289/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18080289/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ScrollView 分页,图像略微向左或向右显示(开始/结束)