【iOS】寒假OC开发项目知识点总结(不全)
第一个界面InitViewController
1.定时器3步
NSTimer* myTimer = ;
NSRunLoop *runloop = ; //获取当前线程的runloop
; //将定时器添加到RunLoop中
2。学会使用UIimageView 的动态展示方法
[*](void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL
finished))completion
代码示例:
- (void)imageViewRun {
//通过这个方法,你可以指定动画时长、动画效果、完成后的操作等。
[UIImageView animateWithDuration:2 animations:^{
self.beforeImageView.frame = CGRectMake((SIZE_WIDTH - 250) / 2 + 125, 280, 2.5, 0.6);
}completion:^(BOOL finished) {
self.beforeImageView.image = ;
;
}];
}
3。学会项目标整个初始化步调
- (void)controllerInit {
HomeViewController *homeViewController = [ init];
GameViewController *gameViewController = [ init];
ShareViewController *shareViewController = [ init];
PersonalViewController *personalViewController = [ init];
UIColor *groundColor = ;
homeViewController.view.backgroundColor = groundColor;
gameViewController.view.backgroundColor = groundColor;
shareViewController.view.backgroundColor = groundColor;
personalViewController.view.backgroundColor = groundColor;
UINavigationController *homeNavigationController = [ initWithRootViewController:homeViewController];
UINavigationController *gameNavigationController = [ initWithRootViewController:gameViewController];
UINavigationController *shareNavigationController = [ initWithRootViewController:shareViewController];
UINavigationController *personalNavigationController = [ initWithRootViewController:personalViewController];
self.array = ;
UITabBarController *tabBarController = [ init];
tabBarController.viewControllers = self.array;
UIColor *titleColor = ;
tabBarController.tabBar.barTintColor = titleColor;
self.tabBarController.tabBar.translucent = NO;
UIColor *tabBarColor = ;
tabBarController.tabBar.backgroundColor = tabBarColor;
//推出视图
tabBarController.modalPresentationStyle = UIModalPresentationFullScreen;
tabBarController.selectedIndex = 2; //设置初始选项为第3个
;
}
HomeViewController
1.UITabBarItem对象
1。可以此使用方法设置属性
[*](void)setTitleTextAttributes:(nullable NSDictionary<NSAttributedStringKey,id> *)attributes
forState:(UIControlState)state
2。可以使用image,selectedImage两个属性,分别体现为选中状态下的图标和选中状态下的图标
使用示例:
UITabBarItem *tabBarItem = [ init];
tabBarItem.title = @"主页";
//下面这是 UITabBarItem 和 UIBarButtonItem 类的方法之一
//字体属性(Font Attributes):
//键:NSFontAttributeName
//值:UIFont 对象
//颜色属性(Color Attributes):
//键:NSForegroundColorAttributeName
//值:UIColor 对象
//阴影属性(Shadow Attributes):
//键:NSShadowAttributeName
//值:NSShadow 对象
} forState:UIControlStateNormal];
, NSFontAttributeName:} forState:UIControlStateSelected];
;
; //用于调整图标的插图,上左下右的偏移量
tabBarItem.image = [imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];//设置未选中状态下的图标
tabBarItem.selectedImage = [imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];//设置选中状态下的图标
self.tabBarItem = tabBarItem;
tabBarItem还有这两个方法:
;
;
属性:
1.title
2.image
3.selectedImage
UIImageView
1.frame
2.image
3.tag
4.backgroundColor
5.userInteractionEnabled
6.contentMode:指定图像的显示模式。
7.isUserInteractionEnabled:指定是否允许用户与图像进行交互。
8.animationImages:指定要在动画中显示的一系列图像。可以将多个图像设置给 animationImages 属性,并通过调用 startAnimating 方法来开始动画。
9…layer.masksToBounds //设置是否剪裁多出来的部门
10…layer.cornerRadius. //设置圆角半径
常用方法:
startAnimating:开始播放动画,如果 animationImages 属性中有多个图像。
stopAnimating:制止播放动画。
isAnimating:检查图像视图是否正在播放动画。
initWithImage::使用给定的图像初始化 UIImageView 对象。
UIScrollView
1.backgroundColor
2.tag
3.delegate
4.scrollEnabeld //是否可以滚动
5.bounces //是否可以回弹
6.showsVerticalScrollIndicator / showsHorizontalScrollIndicator
7.contentSize //指定滚动内容的巨细
8.Masonry
9.contentOffset //指定当前滚动视图内容的偏移量。
10.contentInset //指定滚动内容的内边距
11.isPagingEnabled //指定是否启用分页滚动
常用方法:
scrollRectToVisible:animated::将指定的矩形地区滚动到可见地区,并可以选择是否使用动画结果。
setContentOffset:animated::将内容滚动到指定的偏移量,并可以选择是否使用动画结果。
zoomToRect:animated::将指定的矩形地区进行缩放,并可以选择是否使用动画结果。
flashScrollIndicators:显示滚动视图的滚动条指示器一段时间,以提示用户可以滚动内容。
UIButton
1.layer.masksToBounds //当 masksToBounds 设置为 YES 时,超出图层边界的内容将被裁剪掉,只显示在图层边界内的部门。
2.tag
3.backgroundColor
4.- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state; 方法
5.imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]
6.layer.cornerRadius //设置圆角半径
7.frame
UITapGestureRecognizer
常用属性:
numberOfTapsRequired:一个整数值,指定需要识别的轻鼓掌势的点击次数。默认值为 1,体现单击手势。
numberOfTouchesRequired:一个整数值,指定需要识别的轻鼓掌势所需的触摸点数。默认值为 1,体现单指轻鼓掌势。
delegate:一个遵照 UIGestureRecognizerDelegate 协议的对象,用于处理手势识别器的委托方法。
常用方法:
init(target: Any?, action: Selector?):初始化手势识别器,并指定目标对象和相应方法。通过此初始化方法创建手势识别器对象,并指定在手势识别时调用的目标对象和相应方法。
require(toFail: UIGestureRecognizer):指定一个手势识别器,在另一个手势识别器识别失败时才能识别。通过调用此方法指定手势识别器的依靠关系,可以控制多个手势之间的相互影响。
location(in: UIView?):获取手势在指定视图坐标系中的位置。通过调用此方法,可以获取手势的位置,以便在相应方法中进行相应的处理。
UIAlertController / UIAlertAction (提示框)
三部曲:先创建一个UIAlertController,再创建初始化UIAlertAction,然后addAction,将AlertAction添加到AlertController中,末了讲Controller推出(present出去)
[*](instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
[*](instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
[*](void)addAction:(UIAlertAction *)action;
[*](void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion
UIImagePickerController
1.sourceType
UIImagePickerControllerSourceTypePhotoLibrary //相册
UIImagePickerControllerSourceTypeCamera, //相机
UIImagePickerControllerSourceTypeSavedPhotosAlbum
2.modalPresentationStyle 这个是Controller都有的属性
3.cameraCaptureMode
UIImagePickerControllerCameraCaptureModePhoto,
UIImagePickerControllerCameraCaptureModeVideo
4.delegate
// 实现 UIImagePickerControllerDelegate 委托协议中的方法
[*](void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info;
这个方法中,info属性:
valueForKey:方法
;
UIImagePickerControllerEditedImage
UIImagePickerControllerOriginalImage //这两个是相册常用的,下面是给录像用的
UIImagePickerControllerMediaURL
UIImagePickerControllerMediaType
UIImagePickerControllerMediaURL
第二个界面
UIBarButtonItem
//下方的叫tabBar
//上方的就叫Bar,
UIBarButtonItem:
上方导航栏添加垃圾箱按钮的示例
self.navigationItem.rightBarButtonItem = [ initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(pressDelete)];
UICollectionViewFlowLayout / UICollectionView
UICollectionViewFlowLayout *layout = [ init];
//布局方向为垂直流布局
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.itemSize = CGSizeMake(SIZE_WIDTH / 3 - 20, SIZE_WIDTH / 3 - 20);
1.scrollDirection
2.itemSize
self.collectionView = [ initWithFrame:CGRectMake(0, 90, SIZE_WIDTH, SIZE_HEIGHT - 90) collectionViewLayout:layout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.backgroundColor = ;
forCellWithReuseIdentifier:@"mainCell"];
forCellWithReuseIdentifier:@"firstCell"];
forCellWithReuseIdentifier:@"plusCell"];
;
1.用collectionViewLayout初始化collectionVIew
2.delegate
3.datasource
4.backgroundColor
5.frame
方法:注册cell
[*](void)registerClass:(nullable Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
[*] forCellWithReuseIdentifier:@"mainCell"]; forCellWithReuseIdentifier:@"firstCell"]; forCellWithReuseIdentifier:@"plusCell"]; ;
实现UICollectionView的一系列协议函数
UILongPressGestureRecognizer
常用属性:
minimumPressDuration:长按的最小一连时间,即手指按住屏幕的时间超过该值才被认为是一次长按手势,默认值为0.5秒。
numberOfTouchesRequired:所需触摸数量,即需要的手指数量来触发长按手势,默认值为1。可以根据需要将其设置为大于1的值。
allowableMovement:允许移动的最大隔断,即手指在按住屏幕期间允许的最大移动隔断。如果手指移动的隔断超过此值,则不会触发长按手势。默认值为10点。
常用方法:
init(target: Any?, action: Selector?):初始化方法,用于创建一个UILongPressGestureRecognizer对象,并设置其目标(target)和相应方法(action)。
func location(in: UIView?) -> CGPoint:返回手指在指定视图坐标系中的位置。可以使用此方法获取手指相对于视图的坐标,以便在长按手势的处理方法中进行处理。
func cancelsTouchesInView() -> Bool:返回一个布尔值,指示当手势被识别时是否取消触摸变乱的传递。如果返回true,则手势识别器将取消触摸变乱的传递;如果返回false,则继续传递触摸变乱。默认值为true。
func require(toFail: UIGestureRecognizer):指定一个手势识别器,要求当前手势识别器在指定的手势识别器之前失败才能触发。可以使用此方法来创建手势之间的依靠关系。
使用示例:
//长按功能
self.longPressGestureRecognizer = [ init];
self.longPressGestureRecognizer.minimumPressDuration = 0.5;
;
;
}
//长按触发事件
- (void)handleLongPressRecognizer:(UILongPressGestureRecognizer *)gesture{
switch (gesture.state) {
case UIGestureRecognizerStateBegan:{
NSIndexPath *path = ];
if(path == nil || path.item == 0 || path.item == self.photoArray.count + 1) {
break;
}
;
}
break;
case UIGestureRecognizerStateChanged:
];
break;
case UIGestureRecognizerStateEnded:
;
break;
default:
;
break;
}
}
//设置collectionView的item是否可以移动
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
//移动函数
- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath {
id item = ;
NSInteger movedItem = destinationIndexPath.item;
if (movedItem != 0 && movedItem != self.photoArray.count + 1) {
;
;
}
;
}
//设置边距
//指定该节中每个单元格的内容将与其边界保持15点的隔断
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(15, 15, 15, 15);
}
FMDB用法
//FMDB初始化
- (void)databaseInit {
NSString *photoDoc = ;
NSString *photoFileName = ;
self.photoDataBase = ;
if () {
BOOL result = ;//BLOB:二进制大对象,用于存储二进制数据,在SQLite中,是不区分大小写的
if (result) {
NSLog(@"创表成功");
} else {
NSLog(@"创表失败");
}
}
}
//FMDB查询数据
- (void)queryData {
if () {
// 1.执行查询语句
FMResultSet *photoResultSet = ;
// 2.遍历结果
while () {
NSData *imageData = ;
UIImage *image = ;
;
}
;
}
}
//FMDB插入数据
- (void)insertPhotoDataBase:(UIImage *)image {
NSData *imageData = UIImagePNGRepresentation(image);//用于将 UIImage 对象转换为 PNG 格式的原始数据。
if () {
BOOL result = ; //insert into关键字, values(?,?),?是占位符
if (!result) {
NSLog(@"增加数据失败");
} else {
NSLog(@"增加数据成功");
}
;
}
}
//FMDB删除数据
- (void)deletePhotoData:(UIImage *)image {
NSData *imageData = UIImagePNGRepresentation(image);
if () {
BOOL result = ;//关键词:delete from
if (!result) {
NSLog(@"数据删除失败");
} else {
NSLog(@"数据删除成功");
}
;
}
}
第三个界面
界面控件设计逻辑:
tableView设置在ScrollView上,然后SegmentedControl通过按钮方法,来控制scrollVeiew的contentOffset.x,反过来scrollView也通过contentOffset.x来反过来控制segmentedControl.selectedSegmentIndex
- (void)pressSegmented{
if (_segmentedControl.selectedSegmentIndex == 0) {
;
} else if (_segmentedControl.selectedSegmentIndex == 1) {
;
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.scrollView.contentOffset.x == 0) {
_segmentedControl.selectedSegmentIndex = 0;
} else if (self.scrollView.contentOffset.x == SIZE_WIDTH) {
_segmentedControl.selectedSegmentIndex = 1;
}
}
UISegmentedControl
1.frame
2.backgroundColor
3.tintColor
4.selectedSegmentTintColor. //被选中的栏的颜色
5.设置对一个状态下属性的方法
[*](void)setTitleTextAttributes:(nullable NSDictionary<NSAttributedStringKey,id> *)attributes forState:(UIControlState)state
6.往SegmentedControl里添加元素
;
;
7.设置SegmentedControl选项点击方法
;
8.设置当前选中的元素下标
self.segmentedControl.selectedSegmentIndex = 1;
下面这个总结的挺好的:
常用属性:
selectedSegmentIndex:当前选中的段索引。可以使用这个属性来获取当前选中的段的索引,大概通过设置它来改变选中的段。
numberOfSegments:段的数量。可以使用这个属性来获取 UISegmentedControl 中的段的数量。
tintColor:控件的颜色。可以使用这个属性来设置控件的颜色,包罗段的颜色和选中段的颜色。
isEnabled:控件是否启用。可以使用这个属性来设置控件是否相应用户的交互操作。
常用方法:
setTitle(_:forSegmentAt:):设置指定索引处的段的标题。可以使用这个方法为特定索引的段设置标题。
setImage(_:forSegmentAt:):设置指定索引处的段的图像。可以使用这个方法为特定索引的段设置图像。
setTitleTextAttributes(_:for:):设置段的文本属性。可以使用这个方法为段的文本设置自界说属性,如字体、颜色等。
insertSegment(withTitle:at:animated:):插入一个带有标题的新段。可以使用这个方法在指定位置插入一个新的段,并设置其标题。
removeSegment(at:animated:):移除指定索引处的段。可以使用这个方法移除指定索引处的段。
addTarget(_:action:for:):添加目标-动作对。可以使用这个方法为控件的特定变乱添加目标和对应的动作方法。
PhotoBrowseViewController
添加轻点和长按手势
UITapGestureRecognizer *tapGestureRecognizer = [ initWithTarget:self action:@selector(pressTapClick:)]; //轻点
UILongPressGestureRecognizer *longPressGesture = [ initWithTarget:self action:@selector(longPressClick:)]; //长按
;
;
轻点和长按方法实现
//轻点
- (void)pressTapClick:(UITapGestureRecognizer *)tapGestureRecognizer {
;
}
//长按
- (void)longPressClick:(UILongPressGestureRecognizer *)press {
UIAlertController * alert = ;
UIAlertAction * save = [UIAlertAction actionWithTitle:@"保存到相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//保存图片
;
}];
//取消按钮
UIAlertAction * cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
//添加各个按钮事件
;
;
//弹出sheet提示框
;
}
保存图片到相册
//保存图片到相册
- (void)loadImageFinished:(UIImage *)image {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
self.saveAlertController = ;
;
NSTimer* myTimer = ;
NSRunLoop *runloop = ;
;
}
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //
UIImageWriteToSavedPhotosAlbum 方法接受四个参数:
// image:要保存的图像对象。
// completionTarget:保存完成后的回调目标对象。
// completionSelector:保存完成后的回调方法,用于处理保存结果。
// contextInfo:上下文信息,可以是任意对象。
PhotoFixView
UIActivityIndicatorView小菊花
[*](void)activityIndicatorInit {
self.activityIndicator = [ initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
;
//设置小菊花的frame
self.activityIndicator.frame = CGRectMake((SIZE_WIDTH - 40) / 2 - 100, (SIZE_HEIGHT - 400) / 2 - 100, 200, 200);
self.activityIndicator.transform = CGAffineTransformMakeScale(1.7f, 1.7f);//用来设置 UIActivityIndicatorView 的缩放变更 x轴y轴都当大1.7倍
;
//设置小菊花颜色
self.activityIndicator.color = ;
//设置背景颜色
self.activityIndicator.backgroundColor = ;
//刚进入这个界面会显示控件,并且制止旋转也会显示,只是没有在转动而已,没有设置大概设置为YES的时候,刚进入页面不会显示
self.activityIndicator.hidesWhenStopped = NO;
}
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]