iOS Stretch#

#

Added in version 2.0.1.

The IOSStretchBehavior class is a KivyMD behavior that implements a stretching (rubber-band) effect for iOS-style widgets. When applied to a widget (such as IOSButton), it enables the widget to stretch non-uniformly like rubber when touched and dragged, with contents (text/icon) stretching along with the container, and smoothly returning to normal state upon release.

Key Features:

  • Expansion-only stretching: Widget expands in any drag direction but never shrinks/compresses

  • Minimal effect: Maximum expansion limited to 20% (scale factor 1.0 → 1.2) for subtle visual feedback

  • Direction-sensitive: Uses absolute touch delta values so stretching occurs regardless of drag direction (left/right/up/down)

  • Smooth reset: Implements damped animation (damping factor 0.85) to return to normal state on touch release

  • Glass effect integration: Properly updates shader uniforms and glass rectangle dimensions to maintain visual correctness during stretch

  • Content stretching: Applies canvas transformation (PushMatrix/Scale/PopMatrix) ensuring both glass effect and widget children stretch uniformly

Example#

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

from kivymd.uix.behaviors import IOSGlassBehavior, IOSStretchBehavior
from kivymd.app import MDApp

KV = '''
MDScreen:

    FitImage:
        id: bg_image
        source: "https://picsum.photos/800/600?random=2"

    GlassContainer:
        target_background: bg_image
        border_radius: [dp(26), dp(26), dp(26), dp(26)]
        glass_color: [1.0, 1.0, 1.0, 0.18]
        blur_amount: 10.0
        size_hint: None, None
        size: "400dp", "200dp"
        pos_hint: {"center_x": .5, "center_y": .5}
'''


class GlassContainer(IOSStretchBehavior, IOSGlassBehavior, BoxLayout):
    pass


class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)


Example().run()

API - kivymd.uix.behaviors.ios.stretch_behavior#

class kivymd.uix.behaviors.ios.stretch_behavior.IOSStretchBehavior(**kwargs)#

Behavior that implements a stretching (rubber-band) effect for iOS-style widgets.

on_size(*args)#
on_touch_down(touch)#

Handle touch down events to initiate stretching effect.

on_touch_move(touch)#

Handle touch move events to update stretching effect.

on_touch_up(touch)#

Handle touch up events to reset stretching effect.