我有一个带AVPlayer的应用程序来播放视频.我希望能够检测到用户何时按下遥控器上的按钮.我尝试实现以下方法,但remoteControlReceivedWithEvent()不响应任何控件事件.
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl) {
if (event.subtype == UIEventSubtypeRemoteControlPlay) {
NSLog(@"play");
} else if (event.subtype == UIEventSubtypeRemoteControlPause) {
NSLog(@"pause");
} else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(@"toggle");
}
}
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
// Setup Apple TV control events
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
// Remove Apple TV control events
[super viewWillDisappear:animated];
[[UIApplication …
Run Code Online (Sandbox Code Playgroud) 我试图了解一个视图如何响应它的边界被改变.如果我更改视图的边界原点,它会相应地更改帧原点吗?
例如
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 150, 200)];
greenView.backgroundColor = [UIColor colorWithRed:0.494 green:0.827
blue:0.129 alpha:1];
[self.view addSubview:greenView];
greenView.bounds = CGRectMake(0, 150, greenView.bounds.size.width, greenView.bounds.size.height);
Run Code Online (Sandbox Code Playgroud)
这不会将框架的原点改为(150,300)吗?运行上面的代码似乎没有改变它的框架.(我知道你不是要用边界改变观点位置,这只是一个假设).