【发布时间】:2014-06-27 01:08:57
【问题描述】:
在下面的代码中,带有按钮的子视图会摆动,即从原点水平移动到红色区域并返回。
但它不会收到按钮本身的点击,而是会收到对红色区域的点击。
我想让动画子视图中的这个按钮仅在子视图在 x 轴上移动期间工作。
作为这项技术的初学者,我在这里遇到了困难。
下面分别是.h和.m文件的代码。
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIView *viewWithButton;
}
@property (strong, nonatomic) UIView *viewWithButton;
- (void) animateButton;
@end
ViewController.m
@implementation ViewController
@synthesize viewWithButton;
- (void) animateButton
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:10];
[UIView setAnimationRepeatCount:HUGE_VALF];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint pos = viewWithButton.center;
pos.x = 400;
viewWithButton.center = pos;
[UIView commitAnimations];
}
- (IBAction)btn
{
NSLog(@"Button Tapped");
}
【问题讨论】:
-
我相信你不能在按钮动画时与之交互。尝试使用 NSTimer 并设置按钮框架。
-
感谢您的回复。现在就试试这个..
-
只有一个按钮还是多个?
-
@MohitPopat 我在子视图上只有一个按钮,它是动画的。它不会在具有 400 个中心的相同大小的区域之外执行动画...我没有足够的声望点来为你们提供屏幕截图。
-
我把它给了你,因为你的两个问题。现在享受
标签: ios objective-c uiview uiviewanimation