UIPageControl图片下面的白点,并且和图片同步

类和文件

AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    MainViewController *mainVC = [[MainViewController alloc] init];
    self.window.rootViewController = mainVC;
    [mainVC release];
    
    [_window release];
    
    
    return YES;
}
- (void)dealloc
{
    [_window release];
    [super dealloc];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end

MainViewController.h

#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
@property (nonatomic , retain)UIScrollView *scrollView;
@end

MainViewController.m

#import "MainViewController.h"
@interface MainViewController ()<UIScrollViewAccessibilityDelegate>
@end
@implementation MainViewController
//@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 280, 400)];
    self.scrollView.contentSize = CGSizeMake(280*15, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.delegate = self;  //代理协议方法
    [self.view addSubview:_scrollView];
    [_scrollView release];
    
    for (int i = 0; i < 15; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0*i, 0, 280, 400)];
        UIScrollView *scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(280*(i), 0, 280, 480)];
        scrollView1.delegate = self;
        scrollView1.maximumZoomScale = 2.0;
        scrollView1.minimumZoomScale = 0.5;
        [self.scrollView addSubview:scrollView1];
        [scrollView1 release];
        
        NSString *name = [NSString stringWithFormat:@"a%d.jpg",i];
        imageView.image = [UIImage imageNamed:name];
        [scrollView1 addSubview:imageView];
        [imageView release];
    }
    
   
    
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(20, 420, 280, 20)];
     //设置白点数量
    pageControl .tag = 1000;
    pageControl.numberOfPages = 15;
    pageControl.pageIndicatorTintColor = [UIColor brownColor];//没有选中的颜色
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];//已经被选中的颜色   。。。。
    pageControl.backgroundColor = [UIColor blueColor];
    pageControl.alpha = 0.3;
    //当值改变的时候,调用绑定的方法
    [pageControl addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:pageControl];
    [pageControl release];
    
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return [scrollView.subviews firstObject];
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //只要scrollView滚动,就调用这个方法
    if (scrollView.contentOffset.x > 3940) {
        scrollView.contentOffset = CGPointMake(0, 0);
//        [scrollView setContentOffset:CGPointMake(-50, 0) animated:YES];
    }
    
    else if (scrollView.contentOffset.x < -30)
    {
        scrollView.contentOffset = CGPointMake(3940, 0);
    }
    
    NSLog(@"偏移量%f",scrollView.contentOffset.x);
    //计算当前是第几页
    int page = scrollView.contentOffset.x / scrollView.frame.size.width;
    NSLog(@"%d",page);
    
    UIPageControl *pageControl = (UIPageControl *)[self.view viewWithTag:1000];
   
    //在换不同页面是,原来的页面回到初始位置
    int a = pageControl.currentPage;
     pageControl.currentPage = page;
    if (a != page) {
        for (int i = 0; i < 15; i++) {
            UIScrollView *p  = [self.scrollView.subviews objectAtIndex:i];
            p.zoomScale = 1.0;
        }
    }
    
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    
    NSLog(@"开始减速");
}
- (void)pageAction:(UIPageControl *)pageControl
{
    //pageControl显示的当前页数(从0开始 )
    NSLog(@"第%d页",pageControl.currentPage);
    // 通过调整scrollView的偏移量,让scrollView调整位置
//    _scrollView.contentOffset = CGPointMake(280 * pageControl.currentPage, 0);
    [_scrollView setContentOffset:CGPointMake(280 * pageControl.currentPage, 0) animated:YES];
    
    NSLog(@"翻页");
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
@end
时间: 2024-12-13 02:32:43

UIPageControl图片下面的白点,并且和图片同步的相关文章

Android:ViewPager扩展详解——带有导航的ViewPagerIndicator(附带图片缓存,异步加载图片)

大家都用过viewpager了, github上有对viewpager进行扩展,导航风格更加丰富,这个开源项目是ViewPagerIndicator,很好用,但是例子比较简单,实际用起来要进行很多扩展,比如在fragment里进行图片缓存和图片异步加载. 下面是ViewPagerIndicator源码运行后的效果,大家也都看过了,我多此一举截几张图: 下载源码请点击这里 ===========================================华丽的分割线==============

img只显示图片一部分 或 css设置背景图片只显示图片指定区域

17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左上角为0,0或0%,0%,右下角为高度和宽度,或100%,100%. clip:rect(300px 100px 300px 0px); 设置显示图片的某个区域,分别是上右下左的顺序设置 部分代码:<style type="text/css">img {position:abs

【PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异常】

1 public static void main(String[] args) throws IOException 2 { 3 /** 4 * PDF单页转化为图片输出 注意:英文或图片类的PDF可转化,中文抛异常 5 */ 6 PDDocument doc; 7 try 8 { 9 String inputFile = "F:\\java56班\\eclipse-SDK-4.2-win32\\iText入门基础教程[2].pdf"; 10 String imagepath = &

atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js

atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js 1. 图片按钮的效果总结 1 1.1. 按钮图片自动缩放的. 1 1.2. 不要边框,如果用自定义图片做按钮背景可以设为 false. 2 1.3. 异形按钮 2 1.4. 不绘制焦点 2 1.5. 鼠标经过时的图标 2 1.6. 选中时的图标 2 1.7. 禁用时显示的图标 2 1.8. 可能需要按钮半透明效果 2 2. 图片按钮的实现 2 2.1. 优先模式:button控

鼠标移动到图片上时,显示大图片

HTML标签中的一部分,仅供参考 <tr> <td><input type="checkbox" class="checkbox1"/></td> <td>1002</td> <td>小猫咪</td> <td><img src="img/02.jpg" height="100" width="100&qu

Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

首先我们先看第一个界面吧,使用将手机中的图片扫描出来,然后根据图片的所在的文件夹将其分类出来,并显示所在文件夹里面的一张图片和文件夹中图片个数,我们根据界面元素(文件夹名, 文件夹图片个数,文件夹中的一张图片)使用一个实体对象ImageBean来封装这三个属性 package com.example.imagescan; /** * GridView的每个item的数据对象 * * @author len * */ public class ImageBean{ /** * 文件夹的第一张图片路

点击手机图库图片来获取到点击的图片

在学习安卓期间,都是通过写死一个url来获取一个图片,但是如何实现在没有图片url的情况下通过点击图片来获取url呢,这个问题一直困扰着笔者,今天有时间查阅网上大量资料,经过反复测试终于成功了,现将代码分享如下.由于笔者能力有限,错误之处在所难免,欢迎大家不吝指正,如本篇文章触犯了您的利益,请联系本人.谢谢! 环境:Android Studio+Genymotion 01.布局: <?xml version="1.0" encoding="utf-8"?>

解决ImageView部分图片不能显示的问题(图片已经损坏)

有时候,我们可以检测到有些图片,比如QQ 微信,当我们选择修改头像的时候,对于那些已经损坏的图片,它们会提供一张替换的图. 但是我们如何去判断读出来的图像是已经损坏的呢?用如下方法即可: BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bit = BitmapFactory.decodeFile(path, options); //file

android 将图片通过base64转换为String 将图片String转换为Bitmap

1.Bitmap转换为图片字符串 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //该方法用来压缩图片,第一个参数为图片格式,第二个参数为截取图片的保留率,如当前为90,则保留之前图片90%的区域 bitmap.compress(Bitmap

android 调用系统相机获取图片、调用系统相册获取图片,并对图片进行截取

打开系统相册获取图片并截取,代码相对简单 1 Intent intent = new Intent(Intent.ACTION_GET_CONTENT,null); 2 intent.setType("image/*"); 3 intent.putExtra("crop", "true"); 4 5 //WIDTH 和 HEIGHT指的是截取框的宽高比例,如设WIDTH = 1,HEIGHT = 1,截取框就为正方形 6 intent.putEx