আইওএস 7 এর সাহায্যে অ্যাপল UIMotionEffect
মোশন ইফেক্টগুলি যুক্ত করতে চালু করেছে যা ব্যবহারকারীর ডিভাইসের দিকনির্দেশের সাথে সম্পর্কিত। উদাহরণস্বরূপ, হোম স্ক্রীনে প্যারালাক্স প্রভাব অনুকরণ জন্য, আপনাকে উপশ্রেণী ব্যবহার করতে পারেন UIInterpolationMotionEffect
, যেমন ব্যাখ্যা করেছেন এখানে এবং এখানে শুধু একটি কোড কয়েক লাইন সঙ্গে।
উদ্দেশ্য-সি :
// Set vertical effect
UIInterpolatingMotionEffect *verticalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
verticalMotionEffect.minimumRelativeValue = @(-10);
verticalMotionEffect.maximumRelativeValue = @(10);
// Set horizontal effect
UIInterpolatingMotionEffect *horizontalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-10);
horizontalMotionEffect.maximumRelativeValue = @(10);
// Create group to combine both
UIMotionEffectGroup *group = [UIMotionEffectGroup new];
group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect];
// Add both effects to your view
[myBackgroundView addMotionEffect:group];
সুইফ্ট (@ লুকাসকে ধন্যবাদ):
// Set vertical effect
let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y",
type: .TiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = -10
verticalMotionEffect.maximumRelativeValue = 10
// Set horizontal effect
let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x",
type: .TiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = -10
horizontalMotionEffect.maximumRelativeValue = 10
// Create group to combine both
let group = UIMotionEffectGroup()
group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
// Add both effects to your view
myBackgroundView.addMotionEffect(group)
এছাড়াও, আপনি এটি আরও সহজ করতে বা পুরানো আইওএস সংস্করণগুলিতে এই কার্যকারিতা যুক্ত করার জন্য একগুচ্ছ গ্রন্থাগার সন্ধান করতে পারেন: