@interface ViewController : UIViewController
{
CGPoint beginPoint;
CGPoint nowPoint;
BOOL isInButton;
}
@property (strong,nonatomic) IBOutlet UIButton *mButton;
- (void)viewDidLoad
{
[super viewDidLoad];
isInButton = YES;
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)buttonclick:(id)sender
{
NSLog(@"button tap");
}
- (void)shownslog
{
if (isInButton) {
[mButton setBackgroundImage:[UIImage imageNamed:@"meinv.jpg"] forState:UIControlStateNormal];
NSLog(@"move in button");
}else{
[mButton setBackgroundImage:[UIImage imageNamed:@"images.jpeg"] forState:UIControlStateNormal];
NSLog(@"move out button");
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
beginPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
nowPoint = [touch locationInView:self.view];
if (nowPoint.x <314&&nowPoint.x>6&&nowPoint.y>90&&nowPoint.y<313) {
if (!isInButton) {
isInButton = YES;
[self shownslog];
}
}
else
{
if (isInButton) {
isInButton = NO;
[self shownslog];
}
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (isInButton) {
isInButton = NO;
[self shownslog];
}
}