iOS 14 UIPageControl对比、升级与适配

一、UI层级关系改变

1.iOS 14以前

iOS 14以前
iOS 14以前

2.iOS 14以后

iOS 14以后

iOS 14以后

所以系统 在上级iOS 14以后,会发现UIPageControl的位置会有一定位移。因为之前PageControl的宽度,是单纯由指标图片组成的。现在会被_UIPageControlContentView撑大。如果布局是自适应的写法,会导致位移。
我的修改方式是:

    if(@available(iOS 14.0, *)){
        NSArray *arr = [self.pageControl subviews];
        UIView *ContentView = arr[0];
        CGFloat f = CGRectGetWidth(self.pageControl.bounds)-CGRectGetWidth(ContentView.bounds);
        @weakify(self)
        [self.pageControl mas_updateConstraints:^(MASConstraintMaker *make) {
            @strongify(self)
            make.right.mas_equalTo(self).offset(f/2-10);
        }];
    }

        if(@available(iOS 14.0, *)){
            self.pageControl.backgroundStyle = UIPageControlBackgroundStyleMinimal;
        }
         //self.pageControl再移动10px

二、UIPageControl新增属性

1. UIPageControlBackgroundStyle 背景样式

/// The preferred background style. Default is UIPageControlBackgroundStyleAutomatic on iOS, and UIPageControlBackgroundStyleProminent on tvOS.
@property (nonatomic, assign) UIPageControlBackgroundStyle backgroundStyle API_AVAILABLE(ios(14.0));
UIPageControlBackgroundStyle

2. UIPageControlInteractionState

/// The current interaction state for when the current page changes. Default is UIPageControlInteractionStateNone
@property (nonatomic, assign, readonly) UIPageControlInteractionState interactionState API_AVAILABLE(ios(14.0));

typedef NS_ENUM(NSInteger, UIPageControlInteractionState) {
    /// The default interaction state, where no interaction has occured.
    UIPageControlInteractionStateNone        = 0,
    /// The interaction state for which the page was changed via a single, discrete interaction.
    UIPageControlInteractionStateDiscrete    = 1,
    /// The interaction state for which the page was changed via a continuous interaction.
    UIPageControlInteractionStateContinuous  = 2,
} API_AVAILABLE(ios(14.0));

Apple has provided a custom interaction for our new UIPageControl in iOS14 called InteractionState. It is an enum with two interaction types:

  • Discrete
  • Continuous

苹果为UIPageControl中的新UIPageControl提供了一个自定义的交互UIPageControl ,称为InteractionState 。 它是一个具有两种交互类型的枚举:

  • 离散的
  • 连续的

In iOS 14, the default value of UIPageControl’s interaction is continuous:

在iOS 14中, UIPageControl的交互的默认值是continuous :

You can change the interaction state to discrete by setting the property below to false:

您可以通过将下面的属性设置为false来将交互状态更改为discrete :

/// Returns YES if the continuous interaction is enabled, NO otherwise. Default is YES.
@property (nonatomic, assign) BOOL allowsContinuousInteraction API_AVAILABLE(ios(14.0));

You can also add an observer to change the value of the interactionState property and check the current interaction state with the property below:

您也可以添加观察者以更改interactionState属性的值,并使用以下属性检查当前的交互状态:UIPageControl.InteractionState

Below, I have shared GIFs of these two types of interactions. You can see that continuous interaction helps us to reach any index of our UIPageControl with a drag behavior. For the discrete interaction, we tap on it and we move to the next index one by one.

下面,我共享了这两种交互类型的GIF。 您会看到,持续的交互可以帮助我们通过拖动行为到达UIPageControl任何索引。 对于离散交互,我们点击它,然后一个接一个地移到下一个索引。


UIPageControlInteractionStateDiscrete 离散交互

UIPageControlInteractionStateContinuous 连续交互

3. 自定义指标图片

/// The preferred image for indicators. Symbol images are recommended. Default is nil.
@property (nonatomic, strong, nullable) UIImage *preferredIndicatorImage API_AVAILABLE(ios(14.0));
pageControl.preferredIndicatorImage

4. 为不同的位置设置自定义指标图片

/*!
 * @abstract Returns the override indicator image for the specific page, nil if no override image was set.
 * @param page Must be in the range of 0..numberOfPages
 */
- (nullable UIImage *)indicatorImageForPage:(NSInteger)page API_AVAILABLE(ios(14.0));


/*!
 * @abstract Override the indicator image for a specific page. Symbol images are recommended.
 * @param image    The image for the indicator. Resets to the default if image is nil.
 * @param page      Must be in the range of 0..numberOfPages
 */
- (void)setIndicatorImage:(nullable UIImage *)image forPage:(NSInteger)page API_AVAILABLE(ios(14.0));
1*px3JM5wmB6mPgy8Pfe4JWA.png

参考资料:

1.Take a Look at iOS 14’s New UIPageControl https://medium.com/better-programming/take-a-look-at-ios-14s-new-uipagecontrol-3207a10212b9
2.uipagecontrol_看看iOS 14的新UIPageControl https://blog.csdn.net/weixin_26638123/article/details/108169945

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    wgl0419阅读 6,130评论 1 9
  • 本文主要讲解iOS触摸事件的一系列机制,涉及的问题大致包括: 触摸事件由触屏生成后如何传递到当前应用? 应用接收触...
    baihualinxin阅读 1,160评论 0 9
  • 1. 隐私权限适配 1.1 相册权限 相册新增选择权限类型PHAuthorizationStatusLimited...
    进击的小君君阅读 5,007评论 1 6
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,401评论 16 21
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,498评论 0 11